saprykin / plibsys

Highly portable C system library: threads and synchronization primitives, sockets (TCP, UDP, SCTP), IPv4 and IPv6, IPC, hash functions (MD5, SHA-1, SHA-2, SHA-3, GOST), binary trees (RB, AVL) and more. Native code performance.
MIT License
672 stars 74 forks source link

Problems compiling with static library #86

Closed njbradley closed 3 years ago

njbradley commented 3 years ago

Hi all, I build your library recently and it has worked very well, however, I have not been able to compile any of my programs with the static library. Whenever I try to link my program to the static lib, the linker spits out pages and pages of errors, all undefined reference to various functions.

I built the library with these commands:

cmake .. -DCMAKE_MAKE_PROGRAM=mingw32-make -G"Unix Makefiles"
mingw32-make
ctest

Everything seems to work fine, all of the tests run perfect. I then move the libplibsys.dll.a and libplibsysstatic.a into the lib folder of mingw. However, when I try to compile my code with the static library, it breaks

When I run this command, it compiles and runs smoothly: g++ test.cc -o test.exe -std=c++11 -lplibsys However this command does not work: g++ test.cc -o test.exe -std=c++11 -lplibsysstatic Here are the first couple lines of the error, but it goes on for pages and pages. If it would be useful I can post the whole error message, but from what I can see, it looks like the functions in psocket.c are not able to find any other function.

C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `pp_socket_set_fd_blocking':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:141: undefined reference to `__imp_ioctlsocket'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `pp_socket_set_details_from_fd':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:188: undefined reference to `__imp_getsockopt'
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:226: undefined reference to `__imp_getsockname'
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:289: undefined reference to `__imp_getpeername'
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:295: undefined reference to `__imp_getsockopt'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_init_once':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:320: undefined reference to `__imp_WSAStartup'
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:324: undefined reference to `__imp_WSACleanup'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_close_once':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:339: undefined reference to `__imp_WSACleanup'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_new_from_fd':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:404: undefined reference to `__imp_WSACreateEvent'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_new':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:484: undefined reference to `__imp_socket'
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:534: undefined reference to `__imp_WSACreateEvent'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_get_local_address':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:637: undefined reference to `__imp_getsockname'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_get_remote_address':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:674: undefined reference to `__imp_getpeername'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_check_connect_result':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:735: undefined reference to `__imp_getsockopt'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_set_keepalive':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:775: undefined reference to `__imp_setsockopt'
C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.2/../../../../lib/libplibsysstatic.a(psocket.c.obj): In function `p_socket_bind':
C:/Users/nicho/Programs/Cpp/packages/plibsys-master/src/psocket.c:858: undefined reference to `__imp_setsockopt'

Is there some command line option that I missed either in the building or compiling steps? I looked around but couldn't find any instructions on how to compile statically. Any help would be appreciated!

njbradley commented 3 years ago

Ah, I found the problem, I wasn't linking with the library Ws2_32. I added -lWs2_32 to the compiling and it worked great!