Theldus / wsServer

wsServer - a tiny WebSocket server library written in C
https://theldus.github.io/wsServer
GNU General Public License v3.0
422 stars 80 forks source link

Error building/compiling on mac silicon. #67

Closed Sarang0218 closed 1 year ago

Sarang0218 commented 1 year ago

I am trying to use the wsServer library in my project, but I am encountering the following linker error every time I try to compile my code:

Undefined symbols for architecture arm64:
  "_ws_getaddress", referenced from:
      _onopen in echo-65824f.o
      _onclose in echo-65824f.o
      _onmessage in echo-65824f.o
  "_ws_sendframe", referenced from:
      _onmessage in echo-65824f.o
  "_ws_socket", referenced from:
      _main in echo-65824f.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Although the library builds successfully, it fails to generate the example executables. When I try to compile the examples manually with the following command: clang echo.c -I/Users/Mark/Documents/UnivProject/src/wsServer/include

I receive the same linker error. I would appreciate any help or guidance on how to resolve this issue and use the library successfully in my project. Thank you!

Theldus commented 1 year ago

Hi @Sarang0218, How are you compiling? are you able to build the examples with CMake?, like:

$ git clone https://github.com/Theldus/wsServer.git
$ cd wsServer/
$ mkdir build
$ cd build
$ cmake ..
$ make

if not, what is the full output?

Although the library builds successfully, it fails to generate the example executables. When I try to compile the examples manually with the following command: clang echo.c -I/Users/Mark/Documents/UnivProject/src/wsServer/include

When manually compiling a project, you must specify not only the includes directory, but also the static library and its dependencies. If you want to build echo.c present in this project (in examples/echo), you could do:

$ cd wsServer
$ make
$ cd examples/echo
$ gcc echo.c -I ../../include ../../libws.a -pthread

Maybe your macOS is compiling your library to x86_64 and trying to use it in an arm64 project, please check the architecture the generated object files are too...

Sarang0218 commented 1 year ago

Oh it seems like I forgot to specify the static library, haha. It seems to work great now. Thanks for the quick reply!