gpt4 book ai didi

c++ - macOS ld : symbols not found (x86_64)

转载 作者:行者123 更新时间:2023-11-30 05:04:49 33 4
gpt4 key购买 nike

我有以下错误:

    Undefined symbols for architecture x86_64:
"_inflateEnd", referenced from:
uWS::Hub::~Hub() in main.o
"_inflateInit2_", referenced from:
uWS::Hub::Hub(int, bool, unsigned int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我检查了所有类似的问题及其解决方案,但对我没有任何帮助。

我正在尝试测试 uWebSockets ( https://github.com/uNetworking/uWebSockets ) 并具有以下文件结构:

  • my_app(有 main.cpp)
  • ext/uWebSockets(它是上述存储库的克隆)

所以,我正在做以下事情:

~/ext/uWebSockets$ make                                                                                                                                    
make `(uname -s)`
c++ -std=c++11 -O3 -I src -shared -fPIC src/Extensions.cpp src/Group.cpp src/Networking.cpp src/Hub.cpp src/Node.cpp src/WebSocket.cpp src/HTTPSocket.cpp src/Socket.cpp src/Epoll.cpp -stdlib=libc++ -mmacosx-version-min=10.7 -undefined dynamic_lookup -L/usr/local/opt/openssl/lib -I/usr/local/opt/openssl/include -o libuWS.dylib

并获取/ext/uWebSockets中的libuWS.dylib

然后,我执行以下操作:

~/my_app$ g++ -c main.cpp -o main.o -I../ext/uWebSockets/src -I/usr/local/opt/openssl/include -std=c++11

所以现在我在/my_app 中有了 main.o。但是当我尝试:

~/my_app$ g++ -o start main.o -L../ext/uWebSockets -luWS

我收到上述错误:

Undefined symbols for architecture x86_64:
"_inflateEnd", referenced from:
uWS::Hub::~Hub() in main.o
"_inflateInit2_", referenced from:
uWS::Hub::Hub(int, bool, unsigned int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

这是带 -v 的相同命令:

~/my_app$ g++ -o start main.o -L../ext/uWebSockets -luWS -v
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
"/Library/Developer/CommandLineTools/usr/bin/ld" -demangle -lto_library /Library/Developer/CommandLineTools/usr/lib/libLTO.dylib -dynamic -arch x86_64 -macosx_version_min 10.13.0 -o start -L../ext/uWebSockets main.o -luWS -lc++ -lSystem /Library/Developer/CommandLineTools/usr/lib/clang/9.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"_inflateEnd", referenced from:
uWS::Hub::~Hub() in main.o
"_inflateInit2_", referenced from:
uWS::Hub::Hub(int, bool, unsigned int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

如何正确链接它们?

主要.cpp:

#include <iostream>
#include "uWS.h"

int main() {
uWS::Hub h;

h.onError([](void *user) {
std::cout << "WebSocket: Error has occured" << std::endl;
});

h.onConnection([](uWS::WebSocket<uWS::CLIENT> *ws, uWS::HttpRequest req) {
std::cout << "Client established a remote connection over non-SSL" << std::endl;
});

h.onDisconnection([](uWS::WebSocket<uWS::CLIENT> *ws, int code, char *message, size_t length) {
std::cout << "Client got disconnected with data: " << ws->getUserData() << ", code: " << code << ", message: <" << std::string(message, length) << ">" << std::endl;
});

// url, user, headers, timeout, group client
h.connect("wss://www.test.com/", (void *) 0, {}, 5000);

h.run();
std::cout << "Falling through testConnections" << std::endl;

return 0;
}

最佳答案

最后,我能够修复它。问题出在 zlib 中,我没有包含它。

所以正确的运行方式是 g++ -o start main.o -luWS -lz

关于c++ - macOS ld : symbols not found (x86_64),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48665145/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com