我正在 C++ 中测试模块,但不断收到以下错误:
linker input file unused because linking not done
和
ld: file not found: CMakeFiles/TestModule.dir/src/A.cppm.o
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Run Code Online (Sandbox Code Playgroud)
这是我编写的以下代码:
模块:A.cppm
ld: file not found: CMakeFiles/TestModule.dir/src/A.cppm.o
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Run Code Online (Sandbox Code Playgroud)
我的 main.cpp 文件:
export module A;
export namespace Lib_A {
int getNumberOne() { return 1; }
int getNumberTwo() { return 2; }
}
Run Code Online (Sandbox Code Playgroud)
现在我的 CMakeFile:
cmake_minimum_required(VERSION 3.24)
project(TestModule)
set(CMAKE_CXX_STANDARD 20)
add_executable(TestModule src/main.cpp …Run Code Online (Sandbox Code Playgroud) 我是 C++ 编程新手,在使用以下代码时遇到问题:
#include <iostream>
#include <vector>
using namespace std;
class Absolute {
public:
vector<int> nums;
Absolute(vector<int> nums) {
nums = nums; //<--- this size is not 0
}
vector<int> getNums() { return nums; }
int addr() {
int total = 0;
for(int i=0; i<nums.size(); i++) { //<--- nums.size() here is 0 even though it should not be
total += nums[i];
}
return total;
}
};
int main() {
vector<int> numbers = {1, 3, 3, 4, 5, 6, 7, 8}; …Run Code Online (Sandbox Code Playgroud)