我有一堂课,比如:
基础.h
class Base {
public:
Base();
virtual int getInfo(int i);
protected:
int GetDetail (int iVal);
}
inline int Base::getInfo(int i){
int output = GetDetail(i);
return output;
};
Run Code Online (Sandbox Code Playgroud)
Ib Base.cpp,我定义了GetDetail。
int Base::GetDetail(int i){
int output;
// do work to output
return output;
}
Run Code Online (Sandbox Code Playgroud)
我有一些派生类从它们自己的实现 getInfo() 中调用 GetDetail。
当我从 Base.h 中的虚拟函数定义中删除对 getInfo() 的调用时,代码将使用派生类自己的实现进行编译。
当我使用从内联虚拟函数调用 GetDetail 的虚拟函数进行编译时,链接失败并显示:
对 GetDetail 的未定义引用。
有任何想法吗?
我正在努力编译不是我的项目.我收到此错误:
[sophie@laptop minit]$ g++ -o minit minit.cpp
/tmp/ccxr5oWl.o: In function `main':
minit.cpp:(.text+0x4e6): undefined reference to `minit::MinitAlgo::MinitAlgo(std::string)'
minit.cpp:(.text+0x66c): undefined reference to `minit::MinitAlgo::~MinitAlgo()'
minit.cpp:(.text+0x6af): undefined reference to `minit::MinitAlgo::~MinitAlgo()'
minit.cpp:(.text+0x6df): undefined reference to `minit::MinitAlgo::~MinitAlgo()'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
主程序如下(我将代码减少到最小可能的情况):
#include <iostream>
#include <sstream>
#include <string>
#include "MinitAlgo.h"
int main(int argc, char * argv[]) {
std::string fileName = "/home/table.dat";
minit::MinitAlgo m(fileName);
}
Run Code Online (Sandbox Code Playgroud)
MinitAlgo.h 文件:
#ifndef MINITALGO
#define MINITALGO
#include <string>
#include <vector>
namespace minit {
class MinitAlgo {
public:
MinitAlgo(std::string filename); …Run Code Online (Sandbox Code Playgroud) 我知道这个问题已经被问了很多次了,但我无法真正解决它......所以我有一个src文件夹,其中包含我的main.c源代码,一个存储srclib我的文件的文件夹,以及一个存储我的文件的目录。现在 makefile 正确编译了 lib 并将文件放入文件夹中。包括这样的库:lib.cincludelib.hlib.alibmain.c
#include "lib.h"
Run Code Online (Sandbox Code Playgroud)
它是用-I ../include选项编译的,但是当我编译它时,我得到undefined reference to xxx库中每个函数的错误
那么我错过了什么?
gcc -I/opt/cplex-studio-125/cplex/include -lcplex -L/opt/cplex-studio-125/cplex/lib/x86-64_sles10_4.1/static_pic mipex1.c
Run Code Online (Sandbox Code Playgroud)
我正在尝试从 cplex 编译一个示例。-I选项很好。该-L选项似乎已损坏,因为它找不到函数名称。
错误在哪里?在特定链接中有一个libcplex.a.
/tmp/ccf5sKky.o: In function `main':
mipex1.c:(.text+0x9f): undefined reference to `CPXopenCPLEX'
mipex1.c:(.text+0xee): undefined reference to `CPXgeterrorstring'
mipex1.c:(.text+0x125): undefined reference to `CPXsetintparam'
mipex1.c:(.text+0x222): undefined reference to `CPXcreateprob'
mipex1.c:(.text+0x2e1): undefined reference to `CPXcopylp'
mipex1.c:(.text+0x334): undefined reference to `CPXcopyctype'
mipex1.c:(.text+0x380): undefined reference to `CPXmipopt'
mipex1.c:(.text+0x3cc): undefined reference to `CPXgetstat'
mipex1.c:(.text+0x403): undefined reference to `CPXgetobjval'
mipex1.c:(.text+0x474): undefined reference to `CPXgetnumrows'
mipex1.c:(.text+0x490): undefined reference to `CPXgetnumcols'
mipex1.c:(.text+0x4be): undefined reference to `CPXgetx'
mipex1.c:(.text+0x51c): …Run Code Online (Sandbox Code Playgroud) 我的项目中有2个cpp和3个头文件.当我在VS中编译它时,它运行顺利,我没有收到错误消息.但是当我尝试通过这条线在SSH网络上编译时:
g++ -o program.cpp lineoperations.cpp customer.h transaction.h lineoperations.h
Run Code Online (Sandbox Code Playgroud)
它说:
In function `_start':
(.text+0x20): undefined reference to `main'
Run Code Online (Sandbox Code Playgroud)
不要说"别忘了写主函数",因为它已经存在并且我的项目在VS上工作.该怎么办?
这是我的代码中的相关部分.Program.cpp直到main:
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include "lineoperations.h"
using namespace std;
line bankline;
bool operate(char);
void search(char[]);
void add(char[]);
void removee(char[]);
void transaction();
void printline();
int main(){
bankline.create();
bool end = false;
while (!end) {
end = bankline.decideFunction();
}
bankline.close();
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
它继续,但我猜没有必要粘贴它们.如果你需要查看其他cpp文件或头文件,我也会粘贴它们.
我试图运行mongoose c服务器示例,但是当我尝试编译示例时.我收到以下错误.如果我将它包含在标题中,这些引用怎么会丢失?我在windows下用mingw编译.
gcc echo_server.c -out echo_server
echo_server.c:(.text+0x35): undefined reference to `mg_send'
echo_server.c:(.text+0x4a): undefined reference to `mbuf_remove'
echo_server.c:(.text+0x7f): undefined reference to `mg_mgr_init'
echo_server.c:(.text+0x9b): undefined reference to `mg_bind'
echo_server.c:(.text+0xb7): undefined reference to `mg_bind'
echo_server.c:(.text+0xe7): undefined reference to `mg_mgr_poll'
Run Code Online (Sandbox Code Playgroud)
这是echo_server.c
#include "mongoose.h"
static void ev_handler(struct mg_connection *nc, int ev, void *p) {
struct mbuf *io = &nc->recv_mbuf;
(void) p;
switch (ev) {
case MG_EV_RECV:
mg_send(nc, io->buf, io->len); // Echo message back
mbuf_remove(io, io->len); // Discard message from recv buffer
break;
default:
break;
} …Run Code Online (Sandbox Code Playgroud) c windows compiler-errors undefined-reference mongoose-web-server
不field应该在第 50 行 undefined 吗?我的理解是内部嵌套类对外部类没有可见性,正如我在第 65 行遇到的那样......似乎有点不一致,我希望更好地了解外部嵌套类的可见性以避免任何混淆在将来。
"""######################################### Imports ############################################"""
import turtle
import time
import functools
"""######################################### Key press ##########################################"""
def key_space(): # Resets Level
field.setLevel()
def key_p(): # Skips Level
field.nextLevel()
def key_k(): # For making levels
print([(b.x,b.y) for b in field.getBoxes()])
"""######################################## Interface(s) ########################################"""
def stamp(self): # Interface for drawing polygons.
turtle.goto(self.canvasX+field.offset[0],self.canvasY+field.offset[1])
turtle.shape(self.shape)
turtle.color(self.color)
turtle.stamp()
def frameBoiler(func): #
@functools.wraps(func)
def wrapper_frame_boiler(*args,**kwargs):
turtle.clear()
#turtle.getscreen().bgpic('Untitled.png')
r = func(*args, **kwargs)
turtle.update()
time.sleep(0.05)
return r
return wrapper_frame_boiler
"""######################################### Game Logic …Run Code Online (Sandbox Code Playgroud) python abstract-class nested inner-classes undefined-reference