Closed altarrok closed 2 years ago
I also tried -G "MinGW Makefiles"
But then I get this error:
====================[ Build | server | Debug ]==================================
"C:\Program Files\JetBrains\CLion 2021.3.4\bin\cmake\win\bin\cmake.exe" --build C:\INODev\age-of-io\c --target server -- -j 6
Consolidate compiler generated dependencies of target server
[ 50%] Linking C executable server.exe
C:\Program Files\JetBrains\CLion 2021.3.4\bin\mingw\bin/ld.exe: CMakeFiles\server.dir/objects.a(server.c.obj): in function `onopen':
C:/INODev/age-of-io/c/src/server.c:8: undefined reference to `ws_getaddress'
C:\Program Files\JetBrains\CLion 2021.3.4\bin\mingw\bin/ld.exe: CMakeFiles\server.dir/objects.a(server.c.obj): in function `onclose':
C:/INODev/age-of-io/c/src/server.c:16: undefined reference to `ws_getaddress'
C:\Program Files\JetBrains\CLion 2021.3.4\bin\mingw\bin/ld.exe: CMakeFiles\server.dir/objects.a(server.c.obj): in function `onmessage':
C:/INODev/age-of-io/c/src/server.c:25: undefined reference to `ws_getaddress'
C:\Program Files\JetBrains\CLion 2021.3.4\bin\mingw\bin/ld.exe: C:/INODev/age-of-io/c/src/server.c:38: undefined reference to `ws_sendframe'
C:\Program Files\JetBrains\CLion 2021.3.4\bin\mingw\bin/ld.exe: CMakeFiles\server.dir/objects.a(server.c.obj): in function `main':
C:/INODev/age-of-io/c/src/server.c:48: undefined reference to `ws_socket'
collect2.exe: error: ld returned 1 exit status
mingw32-make[3]: *** [CMakeFiles\server.dir\build.make:100: server.exe] Error 1
mingw32-make[2]: *** [CMakeFiles\Makefile2:82: CMakeFiles/server.dir/all] Error 2
mingw32-make[1]: *** [CMakeFiles\Makefile2:89: CMakeFiles/server.dir/rule] Error 2
mingw32-make: *** [Makefile:123: server] Error 2
After a while, the error changed, now it is the same error with the original issue
Hi @altarrok, are you able to compile the example file as per the instructions for Windows? If so, I believe you are having a problem with your CMakeLists.txt.
Looking at your output:
undefined reference to `__imp_closesocket'
undefined reference to `__imp_send'
undefined reference to `__imp_closesocket'
...
It seems to me that you are forgetting to link your project to the Windows 'ws2_32' library.
Try changing your CMakeLists.txt to something like:
cmake_minimum_required(VERSION 3.21)
project(server C)
set(CMAKE_C_STANDARD 99)
include_directories(include)
add_executable(server
src/server.c)
target_link_libraries(server ${CMAKE_SOURCE_DIR}/src/wsServer/build/libws.a ws2_32)
As far as I know, pthreads is statically added to 'libws.a' but ws2_32 is not... so you need to say you want to link to it too.
I also tried -G "MinGW Makefiles" But then I get this error:
undefined reference to `ws_getaddress' undefined reference to `ws_socket' ...
These functions are from wsServer... it looks like CMake is not finding 'libws.a', or the functions are not present inside the .a
.
You can extract and check with (I think that with the MinGW terminal it is possible):
$ ar x libws.a
$ ls *.o
base64.c.o handshake.c.o sha1.c.o utf8.c.o ws.c.o
$ nm ws.c.o | grep -E "ws_socket|ws_getaddress"
0000000000000604 T ws_getaddress
0000000000001baa T ws_socket
Thanks a lot for the support!!
Adding ws2_32 as target link libraries solved the issue! This is only for windows I believe
Adding ws2_32 as target link libraries solved the issue!
Amazing =)
This is only for windows I believe
Yes, 'ws2_32' belongs to 'WIndows Sockets 2' which implements some network routines supported by default in the libc of other OSes.
Hi, I am a web developer and this is my first time diving into C projects, but I couldn't find any resolution to this problem after some good googleing so I thought maybe someone in this community has dealt with similar issues.
Here is my CMakeLists.txt:
And here is the undefined resources errors: