g ++对库符号的未定义引用 [英] g++ undefined reference to library symbols

查看:168
本文介绍了g ++对库符号的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SFML定义的符号存在链接器错误,但是尽管链接了lib,但我看不到它们是如何发生的. 我使用的是make,目前我正在学习,我想用它构建一个简约的开发环境.

There are linker errors to Symbols defined by SFML, but i cannot see how they occur despite that I linked the lib. I'm using make, which I currently learn and I want to build a minimalistic dev-environment with it.

如果您需要除以下内容以外的其他信息,请给他打电话.我只是想最小化问题的大小.

Give a holler if you need anymore information than the following. I'd just like to minimize the questions size.

XXX@XXX ~/Documents/dev/cpp/proj/beep $ make clean                                                                                                         
rm -f build/*.o build/release/*.o build/debug/*.o build/test/*.o
XXX@XXX ~/Documents/dev/cpp/proj/beep $ make tests
//test obj first
g++ -std=c++14 -Wall -pthread -Iinclude   -c test/Packager.ut.cpp -o   build/test/Packager.ut.o -g3
//now the src obj 
g++ -std=c++14 -Wall -pthread -Iinclude   -c src/ClientAddress.cpp -o build/debug/ClientAddress.o -g3
g++ -std=c++14 -Wall -pthread -Iinclude   -c src/Packager.cpp -o build/debug/Packager.o -g3  
g++ -std=c++14 -Wall -pthread -Iinclude   -c src/Package.cpp -o build/debug/Package.o -g3
Built debug object files.
//now the first test itself
g++ -std=c++14 -Wall -pthread -Iinclude  -lsfml-network  build/test/Packager.ut.o build/debug/ClientAddress.o build/debug/Packager.o build/debug/Package.o -g3  -o bin/test/Packager.ut 
build/test/Packager.ut.o: In function `main':
/home/XXX/Documents/dev/cpp/proj/beep/test/Packager.ut.cpp:69: undefined reference to `sf::IpAddress::IpAddress(char const*)'
build/debug/ClientAddress.o: In function `nw::udp::ClientAddress::ClientAddress()':
/home/XXX/Documents/dev/cpp/proj/beep/src/ClientAddress.cpp:21: undefined reference to `sf::IpAddress::IpAddress(char const*)'
build/debug/ClientAddress.o: In function `nw::udp::operator==(nw::udp::ClientAddress const&, nw::udp::ClientAddress const&)':
/home/XXX/Documents/dev/cpp/proj/beep/src/ClientAddress.cpp:33: undefined reference to `sf::operator==(sf::IpAddress const&, sf::IpAddress const&)'
...

以此类推...在文件中对sf ::的所有提及均被引用

and so on ... every mentionings of sf:: inside the files are quoted

如果我尝试编译其他测试(例如ClientAddress),则会得到相同的错误模式

I get the same error pattern if I try to compile the other tests (for ClientAddress for example)

我现在当然想知道我在哪里错误地链接了什么.如您所见,该库与-lsfml-network链接.我还检查了SMFL的安装,因此至少在标准目录中缺少lib文件的可能性很小.

Of course i now want to know what i linked wrong how there. As you can see the lib is linked with -lsfml-network. I also checked the SMFL installation, so it is at least less likely a lib file gone missing from standard directory.

我猜我在使用g ++,编译和链接命令或smth时出现错误.

I guess there is an error in my usage of g++ , compiling and linking orders or smth.

我的项目树:

>bin
----mainexec
--->test
    ----.ut
>build
--->debug
    ----.o
--->release
    ----.o
--->test
    ----.ut.o
>src
---- .cpp
>include
---- .h
>test
---- .ut.cpp

作为问题的第二部分,我想问一下是否有更好的构建测试的方法,因为我只是将每个src-obj与我的test-obj链接起来,即使还有更多的src-obj超出实际需要的链接.它应该可以工作,并且我不必一直保持测试依赖性,这以后会很麻烦.有什么共同点?

As a second part of the question, I'd like to ask if there is a better way to build tests, because I simply link every src-obj with my test-obj, even if there are way more src-obj linked than it actually needs. It should work and I do not have to maintain my test dependencies all the time, which later would be very cumbersome. What is common ?

推荐答案

sfml-networksfml-system有依赖性.尝试在makefile的链接器命令中的-lsfml-network之前添加-lsfml-system

sfml-network has a dependency on sfml-system. Try add -lsfml-system before -lsfml-network in your linker command in your makefile

这篇关于g ++对库符号的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆