sách gpt4 ăn đã đi

c++ - 体系结构 x86_64 的 undefined symbol -> 体系结构 x86_64 未找到符号

In lại Tác giả: Walker 123 更新时间:2023-11-30 04:51:56 34 4
mua khóa gpt4 giày nike

我正在学习 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)

有没有人知道如何解决这个问题?

34 4 0
Walker 123
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress