草庐IT

fcatch-undefined-behavior

全部标签

C++ undefined reference (即使包含)

如果不在我的main.cpp文件中明确包含TestClass.cpp文件,我将无法编译这段简单的代码。我究竟做错了什么?提前致谢!代码如下:测试类.h#ifndefTESTCLASS_H_#defineTESTCLASS_H_classTestClass{public:staticintfoo();};#endif测试类.cpp#include"TestClass.h"intTestClass::foo(){return42;}主要.cpp#include#include"TestClass.h"usingnamespacestd;intmain(){cout这里是错误:g++main

C++ 错误 : Undefined symbols for architecture x86_64

我正在尝试学习C++并试图解决一个问题,其中给定了一些步骤和您可以爬上这些步骤的可能方法的数量,给出了您可以爬上这些步骤的可能方法的所有排列.因此,例如,如果要爬5步,我可以一次向上移动1步、一次2步或一次3步,我需要打印出1、2和3的所有排列加起来为5:[1,1,1,1,1],[1,1,1,2],....我从这段代码开始(还没有完成),但我得到了这个错误:Undefinedsymbolsforarchitecturex86_64:"_num_steps(int,std::__1::vector>,std::__1::vector>,std::__1::allocator>>>,std

c++ - 对 `JNI_CreateJavaVM' linux 的 undefined reference

我正在尝试熟悉JNIAPI,但无法编译示例C++程序。这是我用来编译的命令,下面是我要编译的程序。我得到的错误是:/tmp/cczyqqyL.o:Infunction`main':/home/nc/Desktop/jni/simple/ctojava/callJava.cpp:16:undefinedreferenceto`JNI_CreateJavaVM'编译:g++-g-I/usr/lib/jvm/java-7-oracle/include/-I/usr/lib/jvm/java-7-oracle/include/linux/-L/usr/bin/java-L/usr/lib/jv

c++ - 错误 C2504 : base class undefined

我以前遇到过很多次这个错误,最终找到了解决办法,但这一次让我难住了。我有一个由“Player”类继承的“Mob”类。这是Mob.h:#pragmaonce#include"PlayState.h"#include"OmiGame/OmiGame.h"#include"resources.h"classPlayState;classMob{private:intframes;intwidth;intheight;inttime;sf::TexturetextureL;sf::TexturetextureR;AnimationanimationL;AnimationanimationR;A

c++ - 带有 O2 的 clang++ 的 undefined reference

我在一个项目上尝试CLang3.4和libc++,但在Release模式下出现奇怪的链接错误:/home/wichtounet/dev/eddic/src/ast/Operator.cpp:17:error:undefinedreferenceto'std::__1::basic_ostream>&std::__1::operator,std::__1::allocator>(std::__1::basic_ostream>&,std::__1::basic_string,std::__1::allocator>const&)'clang:error:linkercommandfail

c++ - 对 staticMetaObject 的 undefined reference

看起来Qt没有处理Q_GADGET宏正确,因为我收到以下错误。有人知道为什么吗?错误:对“Exception::staticMetaObject”的undefinedreference编辑:后来我发现MOC不生成moc_exception.cpp。有时当我切换编译器工具包时它编译得很好但是如果我添加另一个继承异常的类,它又不起作用。问题需要出在MOC中的某个地方,它在某些情况下忽略了Q_GADGET宏?我有Qt5.5.0。project.proCONFIG+=c++11QT+=coreQT-=guiSOURCES+=\main.cppHEADERS+=\nobject.h\except

c++ - ATLAS gemm 将 undefined reference 链接到 'cblas_sgemm'

这是我第一次尝试使用ATLAS。我无法正确链接它。这是一个非常简单的sgemm程序:...#includeconstintM=10;constintN=8;constintK=5;intmain(){float*A=newfloat[M*K];float*B=newfloat[K*N];float*C=newfloat[M*N];//InitializeAandBcblas_sgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans,M,N,K,1.0,A,K,B,N,0.0,C,N);...}当我在带有标准ATLAS安装的linux平台上编译它时,出现

c++ - 为什么 'undefined behaviour'存在?

这个问题在这里已经有了答案:WhyisundefinedbehaviourallowedinC(3个答案)关闭4年前。某些常见的编程语言,尤其是C和C++,具有强烈的未定义行为概念:当您尝试执行超出预期使用方式的某些操作时,这会导致未定义行为。如果发生未定义的行为,编译器可以做它想做的任何事情(包括什么都不做,“时间旅行”等)。我的问题是:为什么存在这种未定义行为的概念?据我所知,如果不是导致未定义的行为,而是使用其预期用途之外的操作会导致大量错误,一个版本的编译器停止工作的程序停止在下一个版本的编译器上工作等,将被阻止编译错误。为什么事情不是这样的?

c++ - 有状态仿函数和 STL : Undefined behaviour

我正在关注这个Functionobjectstutorial复制下面的意大利面:我无法理解以下内容:谓词应始终作为无状态函数对象来实现,以避免意外结果。无法保证算法在内部复制谓词的频率。因此,将谓词实现为有状态函数对象可能会产生意外结果。例子如下:#include#include#include#includeclasspredicate{public:predicate(intcondition):condition_(condition),state_(0){}booloperator()(int){return++state_==condition_;}private:intco

C++ 错误 : undefined reference to `main'

我正在处理一个简单的类List,但是在编译头文件和cpp文件时,出现错误:对`main'的undefinedreference我做错了什么,我该如何解决?这是包含简单header的list.h文件:list.h#ifndefLIST_H#defineLIST_H#includeconstintDEFAULT_CAPACITY=100;classList{public:List();List(intcapacity);~List();voidpush_back(std::strings);intsize()const;std::stringat(intindex)const;privat