我是C++的新手,在Ubuntu 10.04上使用NetBeans IDE准备作业.我使用g ++作为C++编译器.
错误消息:
build/Debug/GNU-Linux-x86/Maze.o: In function `Maze':
Maze/Maze.cpp:14: undefined reference to `Stack<Coordinate>::Stack()'
Maze/Maze.cpp:14: undefined reference to `Stack<Coordinate>::Stack()'
Maze/Maze.cpp:69: undefined reference to `Stack<Coordinate>::push(Coordinate)'
Maze/Maze.cpp:79: undefined reference to `Stack<Coordinate>::isEmpty()'
Maze/Maze.cpp:87: undefined reference to `Stack<Coordinate>::destroy()'
Run Code Online (Sandbox Code Playgroud)
我的相关代码:
#include "Coordinate.h"
#include "Stack.h"
....
....
/**
* Contains the stack object
*
* @var Stack stack
* @access private
*/
Stack<Coordinate> *stack;
...
...
Run Code Online (Sandbox Code Playgroud)
#include "Maze.h"
...
...
Maze::Maze()
{
// IT SHOWS THAT THE FOLLOWING LINE HAS AN ERROR///
stack = …Run Code Online (Sandbox Code Playgroud) 我在这里检查了最常见的未定义的vtable问题引用,虽然这让我更好地理解了发生了什么,但我仍然无法收集足够的信息来弄清楚为什么我有这个错误.
我有一个简单的Square类,最初我试图从Polygon类继承.由于我对C++已经相对了解并且还在学习,所以我还没有尝试过多态性.
无论如何,在我试图摆脱基类(Polygon)后,我认为这可能会有所帮助.不幸的是,我仍然遇到同样的错误,我不知道发生了什么.我所知道的是,最初,Polygon该类需要一个至少包含构造函数定义的源文件,我给了它.这摆脱vtable了Polygon班级的错误.
我的主要问题是我仍然在为Square类继承这个,它应该从Polygon类继承.我想知道的是我如何正确实现这一点以避免在vtable获得多态性的同时获得错误?
码
Polygon.h /的.cpp
#ifndef POLYGON_H
#define POLYGON_H
#include "Shape.h"
#include "vector3f.h"
class Polygon
{
public:
Polygon();
virtual void Collide(Shape &s) = 0;
virtual void Collide(Polygon &p) = 0;
virtual bool Intersects(const Shape &s) = 0;
virtual bool Intersects(const Polygon &s) = 0;
protected:
virtual void Draw() const = 0;
};
#endif // POLYGON_H
//------------------
#include "Polygon.h" …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个游戏引擎,我已经转向 libconfig 来处理我的所有配置需求。我正在构建一个资产管理器,它将使用由 libconfig 解析的配置文件来加载图像、声音等。
当我尝试编译项目时遇到了一个问题。这是导致错误的代码区域:
AssetManager::AssetManager(GameEngine *engine){
_engine = engine;
_config = new Config(); // <-- ERROR ( this is line 5 )
string path = string(ASSET_DIRECTORY);
path += "assets.cfg";
try {
_config->readFile( path.c_str() ); //<-- ERROR ( this is line 11 )
} catch ( const FileIOException &fioex ){
cout << "File exception" << endl;
} catch ( const ParseException &pex ){
cout << "Parse exception" << endl;
}
}
Run Code Online (Sandbox Code Playgroud)
这是错误:
AssetManager.o: In function 'AssetManager':
/home/sean/Code/C++/Ridiculous/src/engine/AssetManager.cpp:5: undefined reference …Run Code Online (Sandbox Code Playgroud) 我正在运行 32 位 Windows 7 Enterprise 和 CodeBlocks 10.05。
我按照本教程设置 OpenCV 2.2 以使用 CodeBlocks。
任何使用 C CodeBlocks API 的程序都可以正常工作 - 它们可以正常编译、链接和运行。但是,当我尝试使用 C++ OpenCV 函数和对象时,.o会生成文件,但出现链接错误,例如:
未定义的引用
`cv::cvtColor(cv::Mat const&, cv::Mat&, int, int)'
经过一番谷歌搜索,我发现这是因为我的搜索目录中没有包含足够的库。但是,我不知道要包含哪些库。
在我的 OpenCV 文件夹中进行了一些搜索后,我也找到了一些.a文件3rdParty/lib并添加了它们。但我的问题仍然存在。
有谁知道我必须包含哪些库才能使我的程序正常工作?
如果您需要更多信息,请告诉我,我会给您。
我的问题已经从我发布的另一个问题发生了变化.我开始使用多个文件,并决定将其全部放在一个main.cpp文件中,以便让它正常工作.
main.cpp中:
#include <iostream>
using namespace std;
class arrayListType {
public:
bool isEmpty() ;
bool isFull() ;
int listSize() ;
int maxListSize() ;
void print() ;
bool isItemAtEqual(int location, int item) ;
virtual void insertAt(int location, int insertItem) = 0;
virtual void insertEnd(int insertItem) = 0;
void removeAt(int location);
void retrieveAt(int location, int& retItem) ;
virtual void replaceAt(int location, int repItem) = 0;
void clearList();
virtual int seqSearch(int searchItem) const = 0;
virtual void remove(int removeItem) = 0;
arrayListType (int …Run Code Online (Sandbox Code Playgroud) 我试图从互联网上编译这一段代码,我的失败是悲惨的.似乎缺少opengl libs - 但它们在那里 - 我检查过.过剩与过剩相关.
系统是Ubuntu 12.04,glxinfo确认视频适配器是openGL 2.1
这是Makefile:
all: ljus
ljus: ljus.c glsl_shader.c calculation.c calculation.h pyramid_func.c
gcc -std=gnu99 -Wall -o ljus -I. -lz -lglut -lGL -lGLU ljus.c
Run Code Online (Sandbox Code Playgroud)
我试图将不同的路径传递给链接器,但没有成功.我究竟做错了什么?
PS这里是'make'输出(相当长 - 抱歉):
/tmp/cc0mDnPf.o: In function `glslCreateProgram':
ljus.c:(.text+0x4f): undefined reference to `glCreateProgramObjectARB'
/tmp/cc0mDnPf.o: In function `glslAttachShaderFromMemory':
ljus.c:(.text+0x118): undefined reference to `glCreateShaderObjectARB'
ljus.c:(.text+0x13c): undefined reference to `glShaderSourceARB'
ljus.c:(.text+0x147): undefined reference to `glCompileShaderARB'
ljus.c:(.text+0x15b): undefined reference to `glAttachObjectARB'
ljus.c:(.text+0x166): undefined reference to `glDeleteObjectARB'
/tmp/cc0mDnPf.o: In function `glslBindAttribute':
ljus.c:(.text+0x3f1): undefined reference to `glBindAttribLocationARB' …Run Code Online (Sandbox Code Playgroud) 我试图使用gcc -Wall -std = c99 hilo.c - ./a.out hilo.c运行此C程序,我收到此错误消息:
hilo.c: In function ‘func’:
hilo.c:6:3: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘pthread_t’ [-Wformat]
hilo.c: In function ‘main’:
hilo.c:14:3: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)(void)’
hilo.c:15:3: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225:12: note: expected ‘void * …Run Code Online (Sandbox Code Playgroud) 我有一堆类具有静态成员,这是一个枚举值.而且我在其他地方有一张地图,这个枚举是关键.现在,如果我在函数中使用模板参数来访问地图,我会得到一个未定义的引用.
为清楚起见,这是一个简化的非工作示例:
template<int T>
struct A
{
static const int Type = T;
}
template<class T>
void fun()
{
cout << map_[T::Type] << endl;
}
map<int, string> map_{{1337, "1337"}};
Run Code Online (Sandbox Code Playgroud)
主要:
fun<A<1337>();
Run Code Online (Sandbox Code Playgroud)
给了我(g ++ 4.7):
undefined reference to `(anonymous namespace)::A<1337>::Type'
Run Code Online (Sandbox Code Playgroud)
不过这个:
template<class T>
void fun()
{
auto key = T::Type;
cout << map_[key] << endl;
}
Run Code Online (Sandbox Code Playgroud)
编译和打印 1337
有人可以解释我这种行为吗?
我正在尝试编译我正在使用ffmpeg库的项目.该项目用C语言编写.头文件适当地包含在源代码中.特别是,它似乎正在使用libavcodec和libavformat,并且这些库在Makefile中与LDFLAGS正确链接.以下是使用的标志:
-lavcodec -lavformat -lswscale -lavutil
Run Code Online (Sandbox Code Playgroud)
现在,因为Ubuntu附带的打包库太过时了,我下载了ffmpeg的最新源代码,编译并安装它.我删除了通过包管理器安装的所有打包库.现在,尽管添加了上面的标志,我得到了很多未定义的引用,我似乎无法解决它.以下是关于未定义引用的输出:
//usr/local/lib/libavcodec.a(cscd.o): In function `decode_frame':
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/cscd.c:91: undefined reference to `uncompress'
//usr/local/lib/libavcodec.a(dxa.o): In function `decode_frame':
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/dxa.c:250: undefined reference to `uncompress'
//usr/local/lib/libavcodec.a(exr.o): In function `pxr24_uncompress':
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/exr.c:784: undefined reference to `uncompress'
//usr/local/lib/libavcodec.a(exr.o): In function `zip_uncompress':
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/exr.c:259: undefined reference to `uncompress'
//usr/local/lib/libavcodec.a(flashsv.o): In function `flashsv_decode_block':
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/flashsv.c:191: undefined reference to `inflateReset'
//usr/local/lib/libavcodec.a(flashsv.o): In function `flashsv2_prime':
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/flashsv.c:158: undefined reference to `inflate'
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/flashsv.c:160: undefined reference to `deflateInit_'
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/flashsv.c:166: undefined reference to `deflate'
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/flashsv.c:167: undefined reference to `deflateEnd'
/home/abhijitv/Downloads/ffmpeg-2.5/libavcodec/flashsv.c:169: …Run Code Online (Sandbox Code Playgroud) 我知道也许这是一个愚蠢的问题,但我看不清楚,我在这里搜索了其他答案,这些答案非常接近我的,但是,我仍然不明白该怎么做.
问题是我无法编译在Windows中使用curses.h的'C'程序(我正在使用Clion和MinGW),当我尝试这样做时,它为curses.h中的函数提供了"未定义的引用" (例如'initscr','clear',......).
通过MinGW安装管理器我安装了"mingw-32-libpdcurses"(有两个可用的两个不同的类:dev和dll;我安装了dll一个).
我正在使用的CMAKE文件是这样的:
cmake_minimum_required(VERSION 3.3)
project(Project1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror -lpdcurses")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}")
file(GLOB Project1_SRC
"*.h"
"*.c"
)
add_executable(Project1 ${Project1_SRC})
Run Code Online (Sandbox Code Playgroud)
我应该更改它以便使用curses.h进行编译?