简体   繁体   English

C ++编译错误:ld:找不到架构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)

[英]C++ compilation error: ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Could someone please explain what am I doing wrong here? 有人可以解释一下我在做什么错吗? I am using macOS Here are the codes: 我正在使用macOS以下是代码:

//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);
}

The command I use to compile is : 我用来编译的命令是:

g++ mainTest.cpp -o mainTest g ++ mainTest.cpp -o mainTest

Here is the error I got: 这是我得到的错误:

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)

I have searched stackoverflow and google but I still can not figure what I did wrong. 我已经搜索了stackoverflow和google,但仍然无法弄清楚自己做错了什么。 Thanks a lot 非常感谢

You didn't link with the test.o . 您没有链接到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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看调用) - ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) C ++ XCODE ld:对于体系结构x86_64 clang找不到符号:错误:链接器命令失败,退出代码为1(使用-v查看调用) - C++ XCODE ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) 在体系结构x86_64 clang中找不到符号:错误:链接器命令失败,退出代码为1(使用-v查看调用) - symbol(s) not found in architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) ld:找不到体系结构x86_64的符号clang:错误:链接器命令失败,退出代码为1(使用-v查看 - ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see “ ld:找不到体系结构x86_64的符号”上的“铛:错误:链接器命令失败,退出代码为1” - “clang: error: linker command failed with exit code 1” on “ld: symbol(s) not found for architecture x86_64” clang:错误:linker 命令失败,退出代码为 1(使用 -v 查看调用) - 架构 x86_64 的未定义符号: - clang: error: linker command failed with exit code 1 (use -v to see invocation) - Undefined symbols for architecture x86_64: Swift Static Library based on C++ sources: linker command failed error: ld: symbol(s) not found for architecture x86_64 clang - Swift Static Library based on C++ sources: linker command failed error: ld: symbol(s) not found for architecture x86_64 clang C++ 错误:ld:未找到体系结构 arm64 的符号 clang:错误:链接器命令失败,退出代码为 1 - C++ Error: ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 编译我的 C++ 程序:clang: error: linker command failed with exit code 1(使用 -v 查看调用) - Compiling my c++ program: clang: error: linker command failed with exit code 1 (use -v to see invocation) ld:找不到用于-lboost_system clang的库:错误:链接器命令失败,退出代码为1(使用-v查看调用) - ld: library not found for -lboost_system clang: error: linker command failed with exit code 1 (use -v to see invocation)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM