C++ C++;:执行命令行生成时出现问题:Singleton::theInstance的未定义引用

C++ C++;:执行命令行生成时出现问题:Singleton::theInstance的未定义引用,c++,makefile,reference,singleton,undefined,C++,Makefile,Reference,Singleton,Undefined,我试图在C++中创建一个单独的类。 以下是错误: CMakeFiles/minisig.dir/src/main.cpp.o : Dans la fonction « main » : main.cpp:(.text+0x9) : référence indéfinie vers « Singleton::theInstance() » main.cpp:(.text+0x12) : référence indéfinie vers « Singleton::theInstance() » co

我试图在C++中创建一个单独的类。 以下是错误:

CMakeFiles/minisig.dir/src/main.cpp.o : Dans la fonction « main » :
main.cpp:(.text+0x9) : référence indéfinie vers « Singleton::theInstance() »
main.cpp:(.text+0x12) : référence indéfinie vers « Singleton::theInstance() »
collect2: error: ld returned 1 exit status
CMakeFiles/minisig.dir/build.make:155: recipe for target 'minisig' failed
make[2]: *** [minisig] Error 1
CMakeFiles/Makefile2:95: recipe for target 'CMakeFiles/minisig.dir/all' failed
make[1]: *** [CMakeFiles/minisig.dir/all] Error 2
Makefile:102: recipe for target 'all' failed
make: *** [all] Error 2
对于我的代码,我只是从这个网站复制粘贴了代码: 看来我联系不到“Singleton.cpp”。
谢谢您的帮助。

好的,所以答案是我在编译之前没有更改我的CMakeLists.txt文件 下次:

  • 修改您的文件
  • 然后命令行:mkdir build、cd build、cmake..、make

您是否创建了
singleton.h
singleton.cpp
?记得把它们添加到你的MaX文件中,这样就可以用Meal.CPP编译了。我猜你不是用< Cord> Stutelon。CPP < /代码>来构建的。谢谢你的回答。对不起,我是C++新手,你如何把文件添加到MaFe文件中?我只做了:mkdir build/cd build/cmake../在列出所有源文件的地方创建一个
CMakeLists.txt
文件。你需要修改它,以便在文件中实际包含
add_executable
命令的所有源文件。好吧,我想我只是很愚蠢,你是对的,我忘了修改CmakeList,非常感谢,我知道这很愚蠢,但我花了一整天时间在这个问题上