【发布时间】:2019-09-14 01:37:26
【问题描述】:
我的教授希望我们在使用 IDE 之前使用终端编译和运行一些 c++ 代码,但我在为其创建 Makefile 时遇到了一些麻烦。我今天去他的办公室寻求帮助,但他的回答很含糊。我一直在网上寻找一个有用的视频,但我遇到了一个我不知道如何解决的错误
我尝试使用以下方法在文本编辑器中编辑 Makefile:
all:
g++ main.cpp myfunc.cpp -o myexe
然后我进入终端窗口并输入:
$ make
我收到的错误是:
g++ main.cpp myfunc.cpp -o myexe
/tmp/ccjSAvna.o: In function `func[abi:cxx11]()':
myfunc.cpp:(.text+0x0): multiple definition of `func[abi:cxx11]()'
/tmp/cczKi1CW.o:main.cpp:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
我不确定此错误消息的含义或如何解决我的问题。
【问题讨论】:
-
听起来您刚刚定义了两个名为
func()的函数。重命名其中之一。 -
那是我的错误,谢谢。
-
这似乎是
main.cpp和myfunc.cpp的问题。请出示相关代码。另请参阅How to create a Minimal, Complete, and Verifiable example。
标签: c++ linux makefile linker-errors