Be sure to have something like this when you compile with C++ trying to access things compiled with C:
#ifdef __cplusplus
extern "C" {
#endif
int timeGetTime(); // it's just a guess it returns int, just be sure to write it correctly here
// anything other declarations go here
#ifdef __cplusplus
}
#endif
That should do.
It's because of differences in name mangling, just like Game_Ender said.
I have a releated problem. I am creating a C++ library with G++, that has needs to have C linkage so it can be loaded by another program. I thought the way to do this was to create some functions that use your classes, then the wrap the declartions for those functions in extern "C". After you have done that, compile and linked the shared library, and you will have a shared library with the C symbols properly exported.
I created a very simple test that has two library both which should export the function "add", one in C, and the other in C++. Then I have two test targets which create a C program. One tries to link with the C library the other with the C++. The C++ one fails to link. Here is the a zip file of the project (http://www.wam.umd.edu/~jlisee/linkTest.zip).
-------------- Build: CppLib in C2C++Lib ---------------
g++ -Iinclude -I/usr/include -c src/adder.cpp -o .objs/src/adder.o
g++ -Iinclude -I/usr/include -c src/cinterface.cpp -o .objs/src/cinterface.o
g++ -shared -L/usr/lib .objs/src/adder.o .objs/src/cinterface.o -o libcpplib.so
-------------- Build: CLib in C2C++Lib ---------------
gcc -Iinclude -I/usr/include -c src/cadd.c -o .objs/src/cadd.o
g++ -shared -L/usr/lib .objs/src/cadd.o -o libclib.so
-------------- Build: testC in C2C++Lib ---------------
gcc -Iinclude -I/usr/include -c src/test.c -o .objs/src/test.o
g++ -L. -L/usr/lib -o testc .objs/src/test.o -lclib
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
-------------- Build: testCpp in C2C++Lib ---------------
g++ -L. -L/usr/lib -o testcpp .objs/src/test.o -lcpplib
.objs/src/test.o: In function `main':
test.c:(.text+0x55): undefined reference to `add'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
I am using Rev 2133. I think I have to export the symbols in another way but I am unsure.
I haven't tried your project, but something seems wrong:
-------------- Build: testCpp in C2C++Lib ---------------
g++ -L. -L/usr/lib -o testcpp .objs/src/test.o -lcpplib
.objs/src/test.o: In function `main':
I see no compiling here. Just linking.
This leads me to believe the object directory for this target is not unique and so it tries to link the object file already created from another of your targets.