C++ 如何使用 g++ 链接 .o 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2203592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 22:30:36 来源:igfitidea点击:
How can I link an .o file using g++
提问by n179911
I am trying to use g++ to compile a .cc file, and I need it to link a .o file.
我正在尝试使用 g++ 来编译一个 .cc 文件,我需要它来链接一个 .o 文件。
So I tried:
所以我试过:
$g++ -o client -I../ipc -L../messages.o client.cc
/usr/bin/ld: error: ../messages.o: can not read directory: Not a directory
And I have tried:
我试过:
$g++ -o client -I../ipc -l../messages.o client.cc
/usr/bin/ld: error: cannot find -l../messages.pb.o
$$ ls -l ../messages.o
-rw-r--r-- 1 hap497 hap497 227936 2010-02-03 22:32 ../messages.o
-rw-r--r-- 1 hap497 hap497 227936 2010-02-03 22:32 ../messages.o
Can you please tell me how to link in a .o file?
你能告诉我如何在 .o 文件中链接吗?
Thank you.
谢谢你。
回答by t0mm13b
$g++ -o client -I../ipc client.cc ../messages.o