c++ - 体系结构 x86_64 的 undefined symbol -> 体系结构 x86_64 未找到符号
In lạiTác giả: Walker 123更新时间:2023-11-30 04:51:56344
我正在学习 C++,我已经知道这行得通了:
helloworld.cpp
#include using namespace std;
int main() { cout << "Hi" << endl; trả về 0; }
我正在使用 MacOS Mojave 并使用命令进行编译
>> g++ helloworld.cpp >> ./a.out
如果工作正常的话。现在我想使用头文件。因此我创建了以下文件:
测试.cpp
#include #include "add.h" using namespace std;
int main() { add(4,7); trả về 0; }
add.h
#pragma once int add(int a, int b);
添加.cpp
#include "add.h" int add(int a, int b) { return a + b; }
当我尝试编译它时,我得到:
>> g++ test.cpp Undefined symbols for architecture x86_64: "add(int, int)", referenced from: _main in test-ebc106.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)
đóng cửa. Câu hỏi này yêu cầu chi tiết gỡ lỗi. Hiện tại nó không chấp nhận câu trả lời. Chỉnh sửa câu hỏi để bao gồm hành vi mong muốn, một vấn đề hoặc lỗi cụ thể và
Tôi là một lập trình viên xuất sắc, rất giỏi!