(C++) glibmm 不会在 Ubuntu/Oneiric 上链接
我在 Ubuntu/Oneiric 上运行最简单的程序时遇到问题:
#include <glibmm/ustring.h>
int main()
{
Glib::ustring s = "Test string";
}
在 make 上使用 Makefile
PACKAGES=glibmm-2.4 glib-2.0 gtkmm-3.0 gtk+-3.0
CC=g++
CFLAGS=`pkg-config --cflags $(PACKAGES)` --std=c++0x
LD=g++
LDFLAGS=`pkg-config --libs $(PACKAGES)`
build: ./main
run: build
./main
clean:
rm ./main.o
rebuild: clean build
./main: ./main.o
$(LD) $(LDFLAGS) ./main.o -o ./main
./main.o: ./main.cc
$(CC) $(CFLAGS) ./main.cc -c -o ./main.o
会出现以下错误:
./main.o: In function `main':
main.cc:(.text+0x15): undefined reference to `Glib::ustring::ustring(char const*)'
main.cc:(.text+0x21): undefined reference to `Glib::ustring::~ustring()'
collect2: ld returned 1 exit status
make: *** [main] Error 1
在 Ubuntu/Maverick 上,完全相同的代码与完全相同的文件链接良好... 如果在 main.o 上使用 ld,它也可以成功链接,但是(正如预期的那样)缺少 _start...
有什么建议吗?
I have problems clinking simplest program on Ubuntu/Oneiric:
#include <glibmm/ustring.h>
int main()
{
Glib::ustring s = "Test string";
}
using Makefile
PACKAGES=glibmm-2.4 glib-2.0 gtkmm-3.0 gtk+-3.0
CC=g++
CFLAGS=`pkg-config --cflags $(PACKAGES)` --std=c++0x
LD=g++
LDFLAGS=`pkg-config --libs $(PACKAGES)`
build: ./main
run: build
./main
clean:
rm ./main.o
rebuild: clean build
./main: ./main.o
$(LD) $(LDFLAGS) ./main.o -o ./main
./main.o: ./main.cc
$(CC) $(CFLAGS) ./main.cc -c -o ./main.o
on make following errors appears:
./main.o: In function `main':
main.cc:(.text+0x15): undefined reference to `Glib::ustring::ustring(char const*)'
main.cc:(.text+0x21): undefined reference to `Glib::ustring::~ustring()'
collect2: ld returned 1 exit status
make: *** [main] Error 1
On Ubuntu/Maverick the exactly same code links well with exactly same file...
if using ld on main.o it links successfully too but (as it was expected) _start is missing...
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试将相关行更改为:
原因是链接器可能会按照命令行上给出的顺序搜索库,因此应始终将它们放在最后以确保安全。
Try changing the relevant lines to this:
The reason is that the linker may search libraries in the order they are given on the command line, so they should always be placed last to be safe.