can't compile my codes...pls help
-
I have recently tried incorporating someone's codes into my codes in visual c++. However their codes are in C. Anyway I have just added their .C and .H files into my project workspace and called one of their functions in my main program. I am unable to cmpile due to the error below: regis.obj : error LNK2001: unresolved external symbol "struct Coordinates __cdecl findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z) Debug/regis.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I understand that the compiler is looking for a library file but the problem is the codes i downloaded only came with the .C and .H file. If i am not wrong, the original codes were compiled successfuly in gcc. Is this a compatability problem?
-
I have recently tried incorporating someone's codes into my codes in visual c++. However their codes are in C. Anyway I have just added their .C and .H files into my project workspace and called one of their functions in my main program. I am unable to cmpile due to the error below: regis.obj : error LNK2001: unresolved external symbol "struct Coordinates __cdecl findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z) Debug/regis.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I understand that the compiler is looking for a library file but the problem is the codes i downloaded only came with the .C and .H file. If i am not wrong, the original codes were compiled successfuly in gcc. Is this a compatability problem?
findRotationMatrix is this declared in .h ?
-
findRotationMatrix is this declared in .h ?
It must be - he didn't encounter any compilation errors. Looks like he's missing a library. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
-
findRotationMatrix is this declared in .h ?
Cillieacc0rd5o4 wrote: findRotationMatrix is this declared in .h ? Yeap,It's declared in .h File as there is no compiler error i.e. Function was found in Header file while compiling but since linker throw the error, it's seem that it enable to get
DEFINATION
offindRotationMatix
function"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
-
It must be - he didn't encounter any compilation errors. Looks like he's missing a library. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com
Ravi Bhavnani wrote: Looks like he's missing a library Oops, you are very FAST :)
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta
-
I have recently tried incorporating someone's codes into my codes in visual c++. However their codes are in C. Anyway I have just added their .C and .H files into my project workspace and called one of their functions in my main program. I am unable to cmpile due to the error below: regis.obj : error LNK2001: unresolved external symbol "struct Coordinates __cdecl findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z) Debug/regis.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I understand that the compiler is looking for a library file but the problem is the codes i downloaded only came with the .C and .H file. If i am not wrong, the original codes were compiled successfuly in gcc. Is this a compatability problem?
I believe your problem is that the function you're trying to use is in the .c file, and you're calling it from the .cpp file. The compiler doesn't decorate names from the .c file, but it does decorate them from the .cpp. That why it appears to be calling: glycemia wrote: findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z) In the header file for the function (the header that goes with the .c file) you should place the following: At the top of the header file
#if defined(__cplusplus) extern "C" { #endif
Then put the rest of the header file in here. and then at the bottom of the same header file:#if defined(__cplusplus) } #endif
That should resolve your problem. Good luck. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193 -
I have recently tried incorporating someone's codes into my codes in visual c++. However their codes are in C. Anyway I have just added their .C and .H files into my project workspace and called one of their functions in my main program. I am unable to cmpile due to the error below: regis.obj : error LNK2001: unresolved external symbol "struct Coordinates __cdecl findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z) Debug/regis.exe : fatal error LNK1120: 1 unresolved externals Error executing link.exe. I understand that the compiler is looking for a library file but the problem is the codes i downloaded only came with the .C and .H file. If i am not wrong, the original codes were compiled successfuly in gcc. Is this a compatability problem?
-
I believe your problem is that the function you're trying to use is in the .c file, and you're calling it from the .cpp file. The compiler doesn't decorate names from the .c file, but it does decorate them from the .cpp. That why it appears to be calling: glycemia wrote: findRotationMatrix(struct Coordinates)" (?findRotationMatrix@@YA?AUCoordinates@@U1@@Z) In the header file for the function (the header that goes with the .c file) you should place the following: At the top of the header file
#if defined(__cplusplus) extern "C" { #endif
Then put the rest of the header file in here. and then at the bottom of the same header file:#if defined(__cplusplus) } #endif
That should resolve your problem. Good luck. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193Thank you so much for your help....your suggestion has solved my problem.... Does this mean I should convert the .c file into .cpp file in the future? Thanks for all your help guys!!
-
Thank you so much for your help....your suggestion has solved my problem.... Does this mean I should convert the .c file into .cpp file in the future? Thanks for all your help guys!!
Not necessarily. It is your choice, but you may run into other problems by converting it to .cpp. If you're using mfc, you'll need to add the stdafx.h header, a wrapper to prevent multiple inclusions would be a good idea, etc. Unless there's a compelling reason to change it to .cpp, then I'd just leave it like it is. The software I work on (a suite of 38 applications and 18 dlls) has one module that is shared with a unix-based hardware component, and that has to be in c, so we just have the one module in c. Glad I could be of help. Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193