-
August 22nd, 2012, 09:59 PM
#1
How to use custom "C" library with C++ codes
I came across a very strength situation while experimenting with creating custom libraries. In my custom library header, I just have this line of code: "double BankAccountBal ( ) ;". my implementation for the library is : "double BankAccountBal ( ) {return 1500.25;};" I then tried compiling this library using C code via setting the Compiled As under Property->C/C++ ->Advanced-> Compiled As to : "Compiled as C Code (/TC). The library compiled fine. Then after the library is built, I include the library in my main project (and properly include all the correct paths, the library link, etc., ), and in my main () I have this line of code: std::cout << BankAccountBal() << std::endl; I tried to build, and got this error : error LNK2019: unresolved external symbol "double __cdecl BankAccountBal(void)" (?BankAccountBal@@YANXZ) referenced in function _wmain. Again, I assured you I have set all the correct paths and link variables. But .... if I went back to the library and compiled as C++ codes instead, via setting the Compiled As under Property->C/C++ ->Advanced-> Compiled As to : "Compiled as C++ Code (/TC). Everything worked !
This suggests that if we are to build C libraries to be used by C++ main codes, there are something missing that need to be set, but I don't know what it is. Any help will be greatly appreciated. Thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|