- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi:
I am switching from CVF to intel fortran for a project. The project was originally developed with CVF and VC6. now I want to use Visual studio 2005 and intel fortran9.1. I set Fortran project as main one and compile the c++ project as a static lib. Building C++ lib without problem. when I build fortran project, there are linking error LNK2019 happened. I am wondering what kind of changes I should make for this migrating? Thanks a lot!
Fortran code:
!====== Interfaces with C++ code ======!
INTERFACE
SUBROUTINE NetGenhelToC4ISR(initialize,YIn,P2CAux)
!DEC$ ATTRIBUTES C, ALIAS:'_Net_Genhel_to_C4ISR' :: NetGenhelToC4ISR
INTEGER*4 :: initialize
REAL*4 :: YIn(50)
REAL*4 :: P2CAux(20)
END SUBROUTINE
SUBROUTINE NetC4ISRToGenhel(initialize,YCmd,C2PAux)
!DEC$ ATTRIBUTES C, ALIAS:'_Net_C4ISR_to_Genhel' :: NetC4ISRToGenhel
INTEGER*4 :: initialize
REAL*4 :: YCmd(50)
REAL*4 :: C2PAux(20)
END SUBROUTINE
SUBROUTINE SetC4ISRIP(IPString,IPLength)
!DEC$ ATTRIBUTES C, ALIAS:'_SetC4ISRIP' :: SetC4ISRIP
CHARACTER*(*) IPString
INTEGER*4 :: IPLength
END SUBROUTINE
END INTERFACE
C++ code:
extern "C" { void SetC4ISRIP (char IPString[], int IPLength); }
void SetC4ISRIP(char IPString[], int IPLength) {
memset(C4ISRHostname,0,sizeof(C4ISRHostname));
memcpy(C4ISRHostname,IPString,IPLength);
C4ISRHostname[IPLength+1] = '\0';
}
// Net_Genhel_to_C4ISR (Genhel version) - sends data to Genhel
extern "C" { void Net_Genhel_to_C4ISR (int initialize,float YIn[50],float P2CAux[20]); }
void Net_Genhel_to_C4ISR(int initialize,float YIn[50],float P2CAux[20]) {
// Declare variables
bool C4ISROutConnected;
Genhel2C4ISR C4ISROut;
switch (initialize) {
case 1:
// Initialize network socket connection
wVersionRequestedC4ISR = MAKEWORD(2,2);
errC4ISR = WSAStartup(wVersionRequestedC4ISR,&wsaDataC4ISR);
hpC4ISR = gethostbyname(C4ISRHostname);
// If host is accessible
if (hpC4ISR != NULL) {
// Establish socket
// Clear address data structure
memset(&saC4ISR,0,sizeof(saC4ISR));
// Copy the address data from the host name lookup
memcpy((char *)&saC4ISR.sin_addr,hpC4ISR->h_addr,hpC4ISR->h_length);
// Set the address family (should be AF_INET)
saC4ISR.sin_family = hpC4ISR->h_addrtype;
// Set the port number (8002 for sending data from Genhel to C4ISR)
saC4ISR.sin_port = htons((u_short)8002);
// Create a datagram socket
C4ISROutSocket = socket(hpC4ISR->h_addrtype,SOCK_DGRAM,0);
// If socket is created
if (C4ISROutSocket >= 0) {
// Connect the socket (should always succeed for UDP)
if (connect(C4ISROutSocket,(struct sockaddr *)&saC4ISR,sizeof(saC4ISR)) < 0) {
// Socket did not connect
// Close socket
closesocket(C4ISROutSocket);
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Socket not connected\n");
}
else {
// Socket connected
// Set the socket to non-blocking mode
u_long arg = 1;
if (ioctlsocket(C4ISROutSocket,FIONBIO,&arg) == 0) {
C4ISROutConnected = TRUE;
}
else {
// Close socket
closesocket(C4ISROutSocket);
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error in setting socket to non-blocking mode\n");
}
}
}
else {
// Socket not created
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Socket not created\n");
}
}
else {
// Host not accessible
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Host not accessible\n");
}
// No break statement - continue on to send trim states
case 0:
case 2:
// Network communication
struct timeval tv;
fd_set reads,writes;
FD_ZERO(&writes);
FD_SET(C4ISROutSocket,&writes);
timeoutC4ISR = 0;
tv.tv_sec = timeoutC4ISR/1000;
tv.tv_usec = (timeoutC4ISR%1000)*1000;
// Define data to send from Genhel to the rotorcraft controller
for (idxC4ISR = 0; idxC4ISR < 50; idxC4ISR++) {
C4ISROut.YIn[idxC4ISR] = YIn[idxC4ISR];
}
for (idxC4ISR = 0; idxC4ISR < 20; idxC4ISR++) {
C4ISROut.P2CAux[idxC4ISR] = P2CAux[idxC4ISR];
}
lengthC4ISR = sizeof(C4ISROut);
select(FD_SETSIZE,&reads,&writes,0,&tv);
if (FD_ISSET(C4ISROutSocket,&writes)) {
// Send data to rotorcraft controller
errC4ISR = send(C4ISROutSocket,(const char *)&C4ISROut,lengthC4ISR,0);
}
else {
// Data not sent
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Data not sent\n");
}
if (initialize == 2) {
// End network communication
// Close socket
closesocket(C4ISROutSocket);
}
break;
default:
// Error
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error in [initialize]\n");
break;
}
}
// Net_C4ISR_to_Genhel
extern "C" { void Net_C4ISR_to_Genhel (int initialize,float YCmd[50],float C2PAux[20]); }
void Net_C4ISR_to_Genhel(int initialize,float YCmd[50],float C2PAux[20]) {
// Declare variables
bool C4ISRInConnected;
C4ISR2Genhel C4ISRIn;
switch (initialize) {
case 1:
// Initialize network socket connection
wVersionRequestedC4ISR = MAKEWORD(2,2);
errC4ISR = WSAStartup(wVersionRequestedC4ISR,&wsaDataC4ISR);
hpC4ISR = gethostbyname(C4ISRHostname);
// If host is accessible
if (hpC4ISR != NULL) {
// Establish socket
// Clear address data structure
memset(&saC4ISR,0,sizeof(saC4ISR));
// Copy the address data from the host name lookup
memcpy((char *)&saC4ISR.sin_addr,hpC4ISR->h_addr,hpC4ISR->h_length);
saC4ISR.sin_addr.s_addr = INADDR_ANY;
// Set the address family (should be AF_INET)
saC4ISR.sin_family = AF_INET;
// Set the port number (8001 for sending data from C4ISR to Genhel)
saC4ISR.sin_port = htons((u_short)8001);
// Create a datagram socket
C4ISRInSocket = socket(AF_INET,SOCK_DGRAM,0);
// If socket is created
if (C4ISRInSocket >= 0) {
// Set the socket to non-blocking mode
u_long arg = 0;
if (ioctlsocket(C4ISRInSocket,FIONBIO,&arg) == 0) {
// Socket connected
C4ISRInConnected = TRUE;
}
else {
// Socket not connected
// Close socket
closesocket(C4ISRInSocket);
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Socket not connected\n");
}
if (bind(C4ISRInSocket,(struct sockaddr *)&saC4ISR,sizeof(saC4ISR)) != 0) {
// Close socket
C4ISRInConnected = FALSE;
closesocket(C4ISRInSocket);
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Socket not bound\n");
}
}
else {
// Socket not created
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Socket not created\n");
}
}
else {
// Host not accessible
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Host not accessible\n");
}
// No break statement - continue on to receive initial data from rotorcraft controller
case 0:
// Network communication
struct timeval tv;
fd_set reads,writes;
FD_ZERO(&reads);
FD_ZERO(&writes);
FD_SET(C4ISRInSocket,&reads);
timeoutC4ISR = 0;
tv.tv_sec = timeoutC4ISR/1000;
tv.tv_usec = (timeoutC4ISR%1000)*1000;
lengthC4ISR = sizeof(C4ISRIn);
// Receive data from rotorcraft controller
errC4ISR = recv(C4ISRInSocket,(char *)&C4ISRIn,lengthC4ISR,0);
if (errC4ISR == lengthC4ISR) {
// Data received from rotorcraft controller
// Separate data out of data structure
for (idxC4ISR = 0; idxC4ISR < 50; idxC4ISR++) {
YCmd[idxC4ISR] = float(C4ISRIn.YCmd[idxC4ISR]);
}
for (idxC4ISR = 0; idxC4ISR < 20; idxC4ISR++) {
C2PAux[idxC4ISR] = float(C4ISRIn.C2PAux[idxC4ISR]);
}
}
else if (errC4ISR > 0) {
// Data received incorrectly
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Data received incorrectly\n");
}
else {
// Data not received
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Data not received\n");
}
break;
case 2:
// End network communication
// Close socket
closesocket(C4ISRInSocket);
break;
default:
// Error
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error in [initialize]\n");
break;
}
}
I am switching from CVF to intel fortran for a project. The project was originally developed with CVF and VC6. now I want to use Visual studio 2005 and intel fortran9.1. I set Fortran project as main one and compile the c++ project as a static lib. Building C++ lib without problem. when I build fortran project, there are linking error LNK2019 happened. I am wondering what kind of changes I should make for this migrating? Thanks a lot!
Fortran code:
!====== Interfaces with C++ code ======!
INTERFACE
SUBROUTINE NetGenhelToC4ISR(initialize,YIn,P2CAux)
!DEC$ ATTRIBUTES C, ALIAS:'_Net_Genhel_to_C4ISR' :: NetGenhelToC4ISR
INTEGER*4 :: initialize
REAL*4 :: YIn(50)
REAL*4 :: P2CAux(20)
END SUBROUTINE
SUBROUTINE NetC4ISRToGenhel(initialize,YCmd,C2PAux)
!DEC$ ATTRIBUTES C, ALIAS:'_Net_C4ISR_to_Genhel' :: NetC4ISRToGenhel
INTEGER*4 :: initialize
REAL*4 :: YCmd(50)
REAL*4 :: C2PAux(20)
END SUBROUTINE
SUBROUTINE SetC4ISRIP(IPString,IPLength)
!DEC$ ATTRIBUTES C, ALIAS:'_SetC4ISRIP' :: SetC4ISRIP
CHARACTER*(*) IPString
INTEGER*4 :: IPLength
END SUBROUTINE
END INTERFACE
C++ code:
extern "C" { void SetC4ISRIP (char IPString[], int IPLength); }
void SetC4ISRIP(char IPString[], int IPLength) {
memset(C4ISRHostname,0,sizeof(C4ISRHostname));
memcpy(C4ISRHostname,IPString,IPLength);
C4ISRHostname[IPLength+1] = '\0';
}
// Net_Genhel_to_C4ISR (Genhel version) - sends data to Genhel
extern "C" { void Net_Genhel_to_C4ISR (int initialize,float YIn[50],float P2CAux[20]); }
void Net_Genhel_to_C4ISR(int initialize,float YIn[50],float P2CAux[20]) {
// Declare variables
bool C4ISROutConnected;
Genhel2C4ISR C4ISROut;
switch (initialize) {
case 1:
// Initialize network socket connection
wVersionRequestedC4ISR = MAKEWORD(2,2);
errC4ISR = WSAStartup(wVersionRequestedC4ISR,&wsaDataC4ISR);
hpC4ISR = gethostbyname(C4ISRHostname);
// If host is accessible
if (hpC4ISR != NULL) {
// Establish socket
// Clear address data structure
memset(&saC4ISR,0,sizeof(saC4ISR));
// Copy the address data from the host name lookup
memcpy((char *)&saC4ISR.sin_addr,hpC4ISR->h_addr,hpC4ISR->h_length);
// Set the address family (should be AF_INET)
saC4ISR.sin_family = hpC4ISR->h_addrtype;
// Set the port number (8002 for sending data from Genhel to C4ISR)
saC4ISR.sin_port = htons((u_short)8002);
// Create a datagram socket
C4ISROutSocket = socket(hpC4ISR->h_addrtype,SOCK_DGRAM,0);
// If socket is created
if (C4ISROutSocket >= 0) {
// Connect the socket (should always succeed for UDP)
if (connect(C4ISROutSocket,(struct sockaddr *)&saC4ISR,sizeof(saC4ISR)) < 0) {
// Socket did not connect
// Close socket
closesocket(C4ISROutSocket);
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Socket not connected\n");
}
else {
// Socket connected
// Set the socket to non-blocking mode
u_long arg = 1;
if (ioctlsocket(C4ISROutSocket,FIONBIO,&arg) == 0) {
C4ISROutConnected = TRUE;
}
else {
// Close socket
closesocket(C4ISROutSocket);
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error in setting socket to non-blocking mode\n");
}
}
}
else {
// Socket not created
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Socket not created\n");
}
}
else {
// Host not accessible
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Host not accessible\n");
}
// No break statement - continue on to send trim states
case 0:
case 2:
// Network communication
struct timeval tv;
fd_set reads,writes;
FD_ZERO(&writes);
FD_SET(C4ISROutSocket,&writes);
timeoutC4ISR = 0;
tv.tv_sec = timeoutC4ISR/1000;
tv.tv_usec = (timeoutC4ISR%1000)*1000;
// Define data to send from Genhel to the rotorcraft controller
for (idxC4ISR = 0; idxC4ISR < 50; idxC4ISR++) {
C4ISROut.YIn[idxC4ISR] = YIn[idxC4ISR];
}
for (idxC4ISR = 0; idxC4ISR < 20; idxC4ISR++) {
C4ISROut.P2CAux[idxC4ISR] = P2CAux[idxC4ISR];
}
lengthC4ISR = sizeof(C4ISROut);
select(FD_SETSIZE,&reads,&writes,0,&tv);
if (FD_ISSET(C4ISROutSocket,&writes)) {
// Send data to rotorcraft controller
errC4ISR = send(C4ISROutSocket,(const char *)&C4ISROut,lengthC4ISR,0);
}
else {
// Data not sent
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error: Data not sent\n");
}
if (initialize == 2) {
// End network communication
// Close socket
closesocket(C4ISROutSocket);
}
break;
default:
// Error
// Error message
fprintf(stderr,"Net_Genhel_to_C4ISR - Error in [initialize]\n");
break;
}
}
// Net_C4ISR_to_Genhel
extern "C" { void Net_C4ISR_to_Genhel (int initialize,float YCmd[50],float C2PAux[20]); }
void Net_C4ISR_to_Genhel(int initialize,float YCmd[50],float C2PAux[20]) {
// Declare variables
bool C4ISRInConnected;
C4ISR2Genhel C4ISRIn;
switch (initialize) {
case 1:
// Initialize network socket connection
wVersionRequestedC4ISR = MAKEWORD(2,2);
errC4ISR = WSAStartup(wVersionRequestedC4ISR,&wsaDataC4ISR);
hpC4ISR = gethostbyname(C4ISRHostname);
// If host is accessible
if (hpC4ISR != NULL) {
// Establish socket
// Clear address data structure
memset(&saC4ISR,0,sizeof(saC4ISR));
// Copy the address data from the host name lookup
memcpy((char *)&saC4ISR.sin_addr,hpC4ISR->h_addr,hpC4ISR->h_length);
saC4ISR.sin_addr.s_addr = INADDR_ANY;
// Set the address family (should be AF_INET)
saC4ISR.sin_family = AF_INET;
// Set the port number (8001 for sending data from C4ISR to Genhel)
saC4ISR.sin_port = htons((u_short)8001);
// Create a datagram socket
C4ISRInSocket = socket(AF_INET,SOCK_DGRAM,0);
// If socket is created
if (C4ISRInSocket >= 0) {
// Set the socket to non-blocking mode
u_long arg = 0;
if (ioctlsocket(C4ISRInSocket,FIONBIO,&arg) == 0) {
// Socket connected
C4ISRInConnected = TRUE;
}
else {
// Socket not connected
// Close socket
closesocket(C4ISRInSocket);
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Socket not connected\n");
}
if (bind(C4ISRInSocket,(struct sockaddr *)&saC4ISR,sizeof(saC4ISR)) != 0) {
// Close socket
C4ISRInConnected = FALSE;
closesocket(C4ISRInSocket);
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Socket not bound\n");
}
}
else {
// Socket not created
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Socket not created\n");
}
}
else {
// Host not accessible
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Host not accessible\n");
}
// No break statement - continue on to receive initial data from rotorcraft controller
case 0:
// Network communication
struct timeval tv;
fd_set reads,writes;
FD_ZERO(&reads);
FD_ZERO(&writes);
FD_SET(C4ISRInSocket,&reads);
timeoutC4ISR = 0;
tv.tv_sec = timeoutC4ISR/1000;
tv.tv_usec = (timeoutC4ISR%1000)*1000;
lengthC4ISR = sizeof(C4ISRIn);
// Receive data from rotorcraft controller
errC4ISR = recv(C4ISRInSocket,(char *)&C4ISRIn,lengthC4ISR,0);
if (errC4ISR == lengthC4ISR) {
// Data received from rotorcraft controller
// Separate data out of data structure
for (idxC4ISR = 0; idxC4ISR < 50; idxC4ISR++) {
YCmd[idxC4ISR] = float(C4ISRIn.YCmd[idxC4ISR]);
}
for (idxC4ISR = 0; idxC4ISR < 20; idxC4ISR++) {
C2PAux[idxC4ISR] = float(C4ISRIn.C2PAux[idxC4ISR]);
}
}
else if (errC4ISR > 0) {
// Data received incorrectly
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Data received incorrectly\n");
}
else {
// Data not received
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error: Data not received\n");
}
break;
case 2:
// End network communication
// Close socket
closesocket(C4ISRInSocket);
break;
default:
// Error
// Error message
fprintf(stderr,"Net_C4ISR_to_Genhel - Error in [initialize]\n");
break;
}
}
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Steve Lionel (Intel)
See this Knowledge Base article. If you are using VS2005, make sure it has SP1 applied.
Thanks Steve. I do have SP1 installed. I read the article and my case is different. I use Fortran project as main program. and intel fortran compiler 9.1. Is there a similar article for my situation?
Wei
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
also, the error messages are:
1>C4ISR.obj : error LNK2019: unresolved external symbol _Net_Genhel_to_C4ISR referenced in function _C4ISR
1>C4ISR.obj : error LNK2019: unresolved external symbol _SetC4ISRIP referenced in function _C4ISR
1>C4ISR.obj : error LNK2019: unresolved external symbol _Net_C4ISR_to_Genhel referenced in function _C4ISR
1>C4ISR.obj : error LNK2019: unresolved external symbol _Net_Genhel_to_C4ISR referenced in function _C4ISR
1>C4ISR.obj : error LNK2019: unresolved external symbol _SetC4ISRIP referenced in function _C4ISR
1>C4ISR.obj : error LNK2019: unresolved external symbol _Net_C4ISR_to_Genhel referenced in function _C4ISR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is this a 32-bit or 64-bit platform? Did you make the C++ library project a "dependent" of the Fortran main project?
I have seen, sometimes, that even if the library project is set as a dependent that the linker is not asked to link in the library. In that case you can add the .lib output from the library project as a "source" for the main.
I have seen, sometimes, that even if the library project is set as a dependent that the linker is not asked to link in the library. In that case you can add the .lib output from the library project as a "source" for the main.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Though the cpu is athlon 64x2, the OS is windows XP PRO. I think this should be 32-bit platform. The compiler I use is IA32. Am I right?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, that's right. Look in the buildlog.htm file in the Debug or Release subfolder at the command generated for the link step. Does it include the name of your C++ library?
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page