C ++:从命令行链接有问题 [英] C++: having trouble linking from command line

查看:92
本文介绍了C ++:从命令行链接有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里开始使用C ++。我正在使用Eclipse CDT进行OSX工作。我有一个项目与一些自定义类和两个文件Test.hpp和Test.cpp - 后来与我的main()方法,运行一些测试,我已经定义和实现在这两个文件。

Just getting started with C++ here. I am working on OSX with Eclipse CDT. I have a project with some custom classes and two files "Test.hpp" and "Test.cpp" - the later with my main() method that runs some tests that I have defined and implemented in these two files.

我可以从Eclipse中编译并运行没有问题,但是当我尝试从命令行用g ++ Test.cpp编译时,我得到了很多链接错误,基本上列出所有在Test.cpp中定义或引用的方法作为未定义的符号。

I can compile and run from Eclipse with no problems, but when I try to compile from the command line with "g++ Test.cpp" I get a lot of linking errors that basically list all the methods defined in or referenced from Test.cpp as undefined symbols.

我以类似的方式编译了几个基本程序(一个头文件和一个实现文件)命令行没有任何问题,但我不知道为什么这一个将不工作。请帮助!

I have compiled a few basic programs (one header file and one implementation file) in similar manner from the command line without any problems, but I can't figure out why this one won't work. Please help!

编辑:我的措辞不清楚,但是我还有其他源文件。接受的答案做了诀窍:g ++ Test.cpp Other1.cpp Other2.cpp。谢谢。

It wasn't clear from my wording, but yes I have other source files too. The accepted answer did the trick: "g++ Test.cpp Other1.cpp Other2.cpp". Thank you.

推荐答案

命令'g ++ Test.cpp'既是编译又是链接。如果你有很多源文件,你应该链接Test.cpp与他们太像g ++ Test.cpp other1.cpp other2.cpp或只是编译所有文件,并链接他们一起后,像'g ++ Test.o other1.o other2 .o'。

Command 'g++ Test.cpp' does both compilation and linking. If you have many source files, you should link Test.cpp with them too like 'g++ Test.cpp other1.cpp other2.cpp' or just compile all files and link them all together later like 'g++ Test.o other1.o other2.o'.

这篇关于C ++:从命令行链接有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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