Here is the setting that I used to build the library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
gcc -IC:\Users\Administrator\Desktop\Project\libadvmath\include -O0 -g3 -Wall -c -fmessage-length=0 -o impl\math_base.o ..\impl\math_base.c
..\impl\math_base.c: In function 'adv_rand':
..\impl\math_base.c:12:13: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
int* datas=(int*)ctx->entropy;
^
..\impl\math_base.c:13:2: warning: implicit declaration of function 'time' [-Wimplicit-function-declaration]
int a=datas[time(0)%2];
^
..\impl\math_base.c: In function 'adv_srand_sf':
..\impl\math_base.c:31:9: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
int* r=(int*)ctx->entropy;
^
g++ -static-libgcc -static-libstdc++ -shared -Wl,-soname=libadvmath.so -Wl,--out-implib=advmath.lib -Wl,--output-def=advmath.def -o liblibadvmath.dll impl\math_base.o
Build complete for project libadvmath
Time consumed: 553 ms.
When I attempt to build the program I got:
1 2 3 4 5 6 7 8
g++ -LC:\Users\Administrator\Desktop\Project\libadvmath\Debug -static-libgcc -static-libstdc++ -o Test.exe src\Test.o -ladvmath
src\Test.o: In function `main':
C:\Users\Administrator\Desktop\Project\Test\Debug/../src/Test.cpp:15: undefined reference to `adv_init()'
C:\Users\Administrator\Desktop\Project\Test\Debug/../src/Test.cpp:17: undefined reference to `adv_rand(_ADV_MATH_CXT*)'
collect2.exe: error: ld returned 1 exit status
Build error occurred, build is stopped
Time consumed: 719 ms.
The first thing I noticed is you are building your library with the -shared flag and naming your .so "libadvmath.so" (I think at least, I have never seen the -soname flag before). But in your test project you are trying to link against -ladvmath. Though I am by no means even close to be ing a regular GCC's user so that might not even matter, but even if that doesn't matter it doesn't hurt to check that the name you are linking against matches the name of the actual library file produced.
Other then that, make sure you double and triple check everything. Stuff like where you library files are (Are they in the correct folder) and other common things like that, since usually these are the cause of 95% of linking errors.
Generally speaking linking errors are quite hard for others to help solve on the forums because there is just so many unknowns.
Because c++ allows function overload, it has to "decorate" the function name in order to differentiate the signatures (name mangling)
By the way, you ought to solve those warnings.
@Z e r e o: the -l flag is just a shortcut, it will strip the `lib' prefix and the `.so', `.a' suffix
and it would be another error if it can't find the library (something like `cannot find -lname')