本文介绍了C ++编译错误:ld:找不到架构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释一下我在做什么错吗?我正在使用macOS
以下是代码:
Could someone please explain what am I doing wrong here? I am using macOSHere are the codes:
// test.h
//test.h
#include <iostream>
#include <string>
class Test
{
public:
Test (std::string, std::string, int);
private:
std::string par1;
std::string par2;
int par3;
};
// test.cpp
//test.cpp
#include <string>
#include <string>
#include "test.h"
using namespace std;
Test::Test (string first, string second, int third)
{
par1 = first;
par2 = second;
par3 = third;
}
// mainTest.cpp
//mainTest.cpp
#include <string>
#include <iostream>
#include "test.h"
using namespace std;
int main()
{
Test test1 ("A", "B", 2);
}
我用来编译的命令是:
g ++ mainTest.cpp -o mainTest
g++ mainTest.cpp -o mainTest
这是我得到的错误:
Undefined symbols for architecture x86_64:
"Test::Test(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, int)", referenced from:
_main in mainTest-056a8f.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我已经搜索了stackoverflow和google,但是我仍然不知道自己做错了什么。非常感谢
I have searched stackoverflow and google but I still can not figure what I did wrong. Thanks a lot
推荐答案
您没有与 test.o
。
g++ -c test.cpp -o test.o
g++ mainTest.cpp test.o -o mainTest
或者您可以同时执行它们:
or you can do them both at once:
g++ maintest.cpp test.cpp -o mainTest
这篇关于C ++编译错误:ld:找不到架构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!