IXWebSocket
IXWebSocket copied to clipboard
Cannot link against IXWebsocket
Hello everyone, I cannot seem to link against IXWebsocket. Been trying for two weeks now. Any help would be greatly appreciated.
My host machine is MacOS and the current CMakeLists target setup looks like this: I have a dynamic library A that links against static library B. Library B has the websocket logic and links against a static library of IXWebsocket.
Library B builds just fine, but when trying to build dynamic library A that links B, I get errors.
+----------------+
| Dynamic |
| Library A |
+----------------+
|
|
|
v
+----------------+
| Static |
| Library B |
+----------------+
|
|
|
v
+--------------------------+
| Static |
| Library IXWebsocket |
+--------------------------+
building IXWebsocket
export BUILD_PATH="build_macos"
rm -rf ${BUILD_PATH}
mkdir ${BUILD_PATH}
cd ${BUILD_PATH}
cmake \
../.. \
-D USE_TLS=1 \
-D USE_OPEN_SSL=1 \
-D USE_TEST=0 \
-D BUILD_SHARED_LIBS=OFF \
-D CMAKE_OSX_ARCHITECTURES="x86_64" \
-D USE_ZLIB=1
make -j
This is the output from terminal:
-- The C compiler identification is AppleClang 14.0.0.14000029
-- The CXX compiler identification is AppleClang 14.0.0.14000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- TLS configured to use openssl
-- Found OpenSSL: /usr/local/opt/openssl/lib/libcrypto.dylib (found version "3.1.1")
-- OpenSSL: 3.1.1
-- Found ZLIB: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk/usr/lib/libz.tbd (found version "1.2.11")
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done (1.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/benni/Documents/ViewPort/IXWebSocket-11.4.3/tools/build_macos
[ 2%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXCancellationRequest.cpp.o
[ 7%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXExponentialBackoff.cpp.o
[ 7%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXBench.cpp.o
[ 13%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXConnectionState.cpp.o
[ 15%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXDNSLookup.cpp.o
[ 13%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXHttp.cpp.o
[ 18%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXGzipCodec.cpp.o
[ 21%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXGetFreePort.cpp.o
[ 23%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXHttpClient.cpp.o
[ 28%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXHttpServer.cpp.o
[ 28%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXNetSystem.cpp.o
[ 31%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterrupt.cpp.o
[ 36%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterruptPipe.cpp.o
[ 36%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterruptFactory.cpp.o
[ 39%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSelectInterruptEvent.cpp.o
[ 42%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocket.cpp.o
[ 44%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSetThreadName.cpp.o
[ 50%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketServer.cpp.o
[ 50%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketConnect.cpp.o
[ 52%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketFactory.cpp.o
[ 55%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketTLSOptions.cpp.o
[ 57%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXStrCaseCompare.cpp.o
[ 63%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUrlParser.cpp.o
[ 63%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUdpSocket.cpp.o
[ 65%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocket.cpp.o
[ 68%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketPerMessageDeflate.cpp.o
[ 71%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketPerMessageDeflateCodec.cpp.o
[ 73%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp.o
[ 78%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketHttpHeaders.cpp.o
[ 78%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketProxyServer.cpp.o
[ 81%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketTransport.cpp.o
[ 84%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXSocketOpenSSL.cpp.o
[ 89%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketCloseConstants.cpp.o
[ 89%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketServer.cpp.o
[ 92%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUserAgent.cpp.o
[ 94%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXUuid.cpp.o
[ 97%] Building CXX object CMakeFiles/ixwebsocket.dir/ixwebsocket/IXWebSocketHandshake.cpp.o
IXWebSocket-11.4.3/ixwebsocket/IXSocketOpenSSL.cpp:304:67: warning: unused parameter 'hostname' [-Wunused-parameter]
const std::string& hostname,
^
1 warning generated.
IXWebSocket-11.4.3/ixwebsocket/IXSocketOpenSSL.cpp:304:67: warning: unused parameter 'hostname' [-Wunused-parameter]
const std::string& hostname,
^
1 warning generated.
[100%] Linking CXX static library libixwebsocket.a
[100%] Built target ixwebsocket
building library B
Then, in my library B CMakeLists.txt I do this:
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
target_compile_definitions(B PUBLIC IXWEBSOCKET_USE_OPEN_SSL IXWEBSOCKET_USE_ZLIB)
target_include_directories(B SYSTEM PUBLIC ${CMAKE_SOURCE_DIR}/openssl/include/)
target_include_directories(B SYSTEM PUBLIC ${IXWEBSOCKET_INCLUDE_DIR})
target_link_libraries(B PUBLIC ${IXWEBSOCKET_LIBRARY} OpenSSL::Crypto)
Not sure if I need the compile definitions here. Also, I think I do not need to include openssl header files and link openssl to B, or do I?
Library B builds and links just fine. The real issue however comes, when I try to build and link library A.
building library A
add_library(ViewPortPlugin SHARED)
target_link_libraries(A PRIVATE B)
using these commands:
#!/bin/bash -eu
export SOLUTION_DIR=$(pwd)/Plugin~
export DYLIB_FILE=$(pwd)/A.dylib
clear
# Remove old dylib file
rm -rf "$DYLIB_FILE"
# Build
cd "$SOLUTION_DIR"
rm -rf out
cmake --preset=macos
cmake --build --preset=release-macos --target=A
###CMakePresets.json
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 20,
"patch": 0
},
"configurePresets": [
{
"name": "default-macos",
"displayName": "Default macOS Config",
"hidden": true,
"binaryDir": "${sourceDir}/out/build/${presetName}",
"generator": "Xcode",
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "x86_64"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"macOS"
]
}
}
},
{
"name": "macos",
"description": "Sets x86_64 and arm64 arch, generator, compilers",
"inherits": "default-macos"
}
],
"buildPresets": [
{
"name": "debug-macos",
"displayName": "Build Debug",
"description": "Debug build for macOS",
"configurePreset": "macos",
"configuration": "Debug",
"verbose": true
},
{
"name": "release-macos",
"displayName": "Build Release",
"description": "Release build for macOS",
"configurePreset": "macos",
"configuration": "Release",
"cleanFirst": true
}
]
}
I get this error:
Ld /Users/ben/Documents/AProjectRootFolder/B/Runtime/Plugins/macOS/libA.dylib normal (in target 'A' from project 'A & B')
cd /Users/ben/Documents/AProjectRootFolder/B/Plugin\~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -target x86_64-apple-macos13.0 -dynamiclib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -L/Users/ben/Documents/AProjectRootFolder/B/Plugin\~/out/build/macos/AProjectRootFolder/EagerLinkingTBDs -L/Users/ben/Documents/AProjectRootFolder/B/Runtime/Plugins/macOS -F/Users/ben/Documents/AProjectRootFolder/B/Plugin\~/out/build/macos/AProjectRootFolder/EagerLinkingTBDs -F/Users/ben/Documents/AProjectRootFolder/B/Runtime/Plugins/macOS -filelist /Users/ben/Documents/AProjectRootFolder/B/Plugin\~/out/build/macos/AProjectRootFolder/A.build/Release/A.build/Objects-normal/x86_64/A.LinkFileList -install_name @rpath/libA.dylib -fobjc-link-runtime -ObjC -dynamiclib -Wl,-headerpad_max_install_names /Users/ben/Documents/AProjectRootFolder/B/Plugin\~/out/build/macos/AProjectRootFolder/Release/libB.a /Users/ben/Documents/AProjectRootFolder/B/Plugin\~/IXWebsocket/lib/macos/libixwebsocket.a /usr/local/Cellar/openssl@3/3.1.1/lib/libcrypto.a /Users/ben/Documents/AProjectRootFolder/B/Plugin\~/A/lib/macos/libA.a -Xlinker -framework -Xlinker Foundation -Xlinker -framework -Xlinker AVFoundation -Xlinker -framework -Xlinker ApplicationServices -Xlinker -framework -Xlinker CoreServices -Xlinker -framework -Xlinker CoreAudio -Xlinker -framework -Xlinker CoreVideo -Xlinker -framework -Xlinker CoreMedia -Xlinker -framework -Xlinker AudioToolbox -Xlinker -framework -Xlinker VideoToolbox -Xlinker -framework -Xlinker Metal -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/ben/Documents/AProjectRootFolder/B/Plugin\~/out/build/macos/AProjectRootFolder/A.build/Release/A.build/Objects-normal/x86_64/A_dependency_info.dat -o /Users/ben/Documents/AProjectRootFolder/B/Runtime/Plugins/macOS/libA.dylib
Undefined symbols for architecture x86_64:
"_SSL_CTX_ctrl", referenced from:
ix::SocketOpenSSL::openSSLCreateContext(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXSocketOpenSSL.cpp.o)
ix::SocketOpenSSL::accept(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXSocketOpenSSL.cpp.o)
"_SSL_ctrl", referenced from:
ix::SocketOpenSSL::connect(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&, std::__1::function<bool ()> const&) in libixwebsocket.a(IXSocketOpenSSL.cpp.o)
"_SSL_get1_peer_certificate", referenced from:
ix::SocketOpenSSL::openSSLCheckServerCert(ssl_st*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXSocketOpenSSL.cpp.o)
"_deflate", referenced from:
bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
bool ix::WebSocketPerMessageDeflateCompressor::compressData<ix::IXWebSocketSendData, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(ix::IXWebSocketSendData const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
bool ix::WebSocketPerMessageDeflateCompressor::compressData<std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > >(std::__1::vector<unsigned char, std::__1::allocator<unsigned char> > const&, std::__1::vector<unsigned char, std::__1::allocator<unsigned char> >&) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
ix::gzipCompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libixwebsocket.a(IXGzipCodec.cpp.o)
"_deflateEnd", referenced from:
ix::WebSocketPerMessageDeflateCompressor::~WebSocketPerMessageDeflateCompressor() in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
ix::gzipCompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libixwebsocket.a(IXGzipCodec.cpp.o)
"_deflateInit2_", referenced from:
ix::WebSocketPerMessageDeflateCompressor::init(unsigned char, bool) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
ix::gzipCompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libixwebsocket.a(IXGzipCodec.cpp.o)
"_inflate", referenced from:
ix::WebSocketPerMessageDeflateDecompressor::decompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
ix::gzipDecompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXGzipCodec.cpp.o)
"_inflateEnd", referenced from:
ix::WebSocketPerMessageDeflateDecompressor::~WebSocketPerMessageDeflateDecompressor() in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
ix::gzipDecompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXGzipCodec.cpp.o)
"_inflateInit2_", referenced from:
ix::WebSocketPerMessageDeflateDecompressor::init(unsigned char, bool) in libixwebsocket.a(IXWebSocketPerMessageDeflateCodec.cpp.o)
ix::gzipDecompress(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in libixwebsocket.a(IXGzipCodec.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Summary
I have a static library B, that links static library IXWebsocket built with -DUSE_TLS=1 -DUSE_OPEN_SSL=1 -DUSE_ZLIB=1. Library B builds just fine, but when trying to build dynamic library A that links B, I get errors.
Any help would be greatly appreciated!