我的主目录中有以下目录.
资源
包括
库
在源目录中,我有以下文件:
a.c
#include <stdio.h>
#include "a.h"
extern void function(void);
int main()
{
printf("PREDEFINED = %d\n",PREDEFINED);
function();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
b.c
#include <stdio.h>
void function()
{
printf("Hello from function\n");
}
Run Code Online (Sandbox Code Playgroud)
a.h
#define PREDEFINED 100
Run Code Online (Sandbox Code Playgroud)
我编译了bc并将bo移动到Lib文件夹.
然后我从source文件夹中尝试了以下命令
gcc -Wall -o temp a.c -I../include -L../Lib
Run Code Online (Sandbox Code Playgroud)
但它显示以下错误a.c: undefined reference to函数`
`
但是当我使用以下命令时,它会生成输出文件temp而没有任何错误
gcc -Wall -o temp a.c -I../include ../Lib/b.o
Run Code Online (Sandbox Code Playgroud)
我哪里错了?
我不确定我做错了什么,我认为所有内容都只定义了一次,所有内容都正确关联,但我想情况并非如此......
这是我的编译器给我的错误:
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static int Powerup_Health::g_refCount" (?g_refCount@Powerup_Health@@0HA)
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static class DBModel * Powerup_Health::g_pModel" (?g_pModel@Powerup_Health@@0PAVDBModel@@A)
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static int Powerup_QuadDamage::g_refCount" (?g_refCount@Powerup_QuadDamage@@0HA)
1>StaticElements.obj : error LNK2001: unresolved external symbol "private: static class DBModel * Powerup_QuadDamage::g_pModel" (?g_pModel@Powerup_QuadDamage@@0PAVDBModel@@A)
Run Code Online (Sandbox Code Playgroud)
码:
StaticElements.h
#pragma once
#include "D3DUtil.h"
class ContentManager;
class Level;
class GraphCamera;
class Powerup_Health;
class Powerup_QuadDamage;
class StaticElements
{
public:
StaticElements(){};
~StaticElements(){};
void PreLevelInitialisation(Level* pLevel);
void …Run Code Online (Sandbox Code Playgroud) 我发现了一些C++ 11的功能并且有问题.我有一个成员函数'call'
class cscript
{
public:
template <typename ret_t, typename... params>
bool call(ret_t &ret, const char * name, params... parameters);
....
Run Code Online (Sandbox Code Playgroud)
执行:
template <typename ret_t, typename... params>
bool cscript::call(ret_t &ret, const char * name, params... parameters)
{
ret_t (*func)(params...);
func = (decltype(func)) tcc_get_symbol(tcc, name);
if (!func)
return true;
ret = func(parameters...);
return false;
}
Run Code Online (Sandbox Code Playgroud)
链接时显示以下错误:
obj\Release\main.o:main.cpp:(.text.startup+0xcc)||undefined reference to `bool cscript::call<int, int, int>(int&, char const*, int, int)'|
Run Code Online (Sandbox Code Playgroud)
电话示例:
script.call(ret, "sum", 2, 3);
Run Code Online (Sandbox Code Playgroud)
有关如何使这项工作的任何建议?
我已经安装了OpenSSL sudo apt-get install openssl-dev.当我尝试使用Netbeans它编译它时会出现以下错误.我该如何解决这个问题?
g++ -lssl -o dist/Debug/GNU-Linux-x86/cppapplication_2 build/Debug/GNU-Linux-x86/main.o -L/home/sercan/Desktop/openssl-0.9.8h-1-lib/lib
build/Debug/GNU-Linux-x86/main.o: In function `main':
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:46: undefined reference to `OPENSSL_add_all_algorithms_noconf'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:48: undefined reference to `ERR_load_crypto_strings'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:58: undefined reference to `d2i_PKCS12_fp'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:66: undefined reference to `ERR_print_errors_fp'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:72: undefined reference to `PKCS12_parse'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:76: undefined reference to `ERR_print_errors_fp'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:82: undefined reference to `PKCS12_free'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:96: undefined reference to `PEM_write_PrivateKey'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:104: undefined reference to `PEM_write_X509_AUX'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:108: undefined reference to `sk_num'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:114: undefined reference to `sk_value'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:114: undefined reference to `PEM_write_X509_AUX'
/home/sercan/NetBeansProjects/CppApplication_2/main.cpp:112: undefined …Run Code Online (Sandbox Code Playgroud) 我正在尝试编译以下实现上下文切换的c ++代码(下载页面上有更多信息):
这需要一些升级库.我从boost.org下载了最新版本,并按照网站上的说明构建了所有需要构建的库.我还修改了归档中包含的makefile来添加boost lib路径和boost_system,但是我仍然遇到错误.这是我正在使用的makefile:
PROGRAM = cts
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
CFLAGS = -Wall
LDFLAGS = -lboost_program_options -lboost_filesystem -lboost_system
$(PROGRAM): $(OBJECTS) Makefile
g++ $(CFLAGS) -L/home/users/mnembrini/opt/boost/lib $(LDFLAGS) -o $(PROGRAM) $(OBJECTS)
# Include known dependecies from -MMD
#-include $(OBJECTS:.o=.d)
%.o: %.cpp
g++ -MMD $(CFLAGS) -I/home/users/mnembrini/opt/boost/include -c $<
clean:
rm -f $(OBJECTS) *.d
.PHONY: clean
Run Code Online (Sandbox Code Playgroud)
其中boost位于〜/ opt/boost(constains lib和include subdir).这是链接错误:
mnembrini@meem:~/src/cts-v1 $ make
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c ac.cpp
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c cts.cpp
cts.cpp: In …Run Code Online (Sandbox Code Playgroud) 我已经编写了一个模板类,用于地图/字典数据结构,并且不断收到这个奇怪的错误(ERROR LNK2019:未解析的外部符号)
码:
AssArray.h:
#pragma once
template <class K,class D>
class AssArray
{
int _size;
int _position;
D* _data;
K* _key;
public:
AssArray(int);
~AssArray(void);
const D& operator [](K k) const;
D& operator [](K k);
};
Run Code Online (Sandbox Code Playgroud)
AssArray.cpp:
#include "StdAfx.h"
#include "AssArray.h"
template <class K,class D>
AssArray<K,D>::AssArray(int size)
{
_size=size;
_data = new D[size];
_key = new K[size];
_position=0;
}
template <class K,class D>
AssArray<K,D>::~AssArray(void)
{
delete[] _data;
delete[] _key;
}
template <class K,class D>
const D& AssArray<K,D>::operator [](K k) const
{ …Run Code Online (Sandbox Code Playgroud) 我知道......以某种方式的基础知识,但我不明白。我读到我可以将我的函数定义放在我的头文件中,然后包含它。到目前为止我从未这样做过,因为我喜欢我在 .cpp 文件中的定义与它在头文件中的声明分开。
现在我只有两个函数,我不想要这些定义的额外文件。
头文件.h
const QString reviewToString(const int); //Declaration - do I even need it now?
const QString statusToString(const int); //Declaration - do I even need it now?
const QString reviewToString(const int r) //Definition
{
switch(r)
{
case 0:
return "Excellent";
case 1:
return "Great";
case 2:
return "Okay";
case 3:
return "Poor";
case 4:
return "Terrible";
default:
return "Unknown";
}
}
const QString statusToString(const int s) //Definition
{
switch(s)
{
case 0:
return "Watched";
case 1:
return "Bought"; …Run Code Online (Sandbox Code Playgroud) 此 C++ 代码在编译时产生链接器错误:
// A.h
class A {
public:
static void f();
private:
static std::vector<int> v;
};
// A.cpp
void A::f() {
// this line is causing trouble
int i = v.size();
}
Run Code Online (Sandbox Code Playgroud)
将向量声明移动到 cpp 文件中是可行的。但是我想了解"Undefined symbols"上面代码中的链接器错误原因。是什么导致了上述代码中的链接器错误?
我有这个简单的程序,它会创建一个密码提示.我安装了Visual Studio 2012和2010.它适用于2010年,但在2012年我收到此错误:unresolved external symbol __report_rangecheckfailure referenced in function main.此外,我通过将所有内容从main移动到另一个函数来修改代码.这适用于两个版本.
某些库肯定存在一些问题,但哪一个,我该如何解决呢?谢谢.
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
int key, i;
char pwd[64];
printf("Enter passphrase: ");
key=getch();
i=0;
while (key!=13)
{
cout<<"*";
pwd[i++]=key;
key=getch();
}
pwd[i++]='\0';
cout<<strlen(pwd)<<endl;
for (i=0; i<strlen(pwd); i++)
cout<<pwd[i]<<endl;
getch();
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Code :: Blocks v 16.1.0.0以及它附带的MINGW.链接器存在问题.我无法使用单个头/源文件链接到源文件#include "sth".为了缩小问题,我的项目中只有1个源文件和1个头文件,但无论我使用什么文件和我尝试的选项,我都无法绕过这个错误.
这是构建日志
-------------- Build: Debug in MISC (compiler: GNU GCC Compiler)---------------
gcc.exe -Wall -Wextra -Wall -g -std=c99 -c C:\Users\username\Documents\CodeBlocks\C\MISC\readFileByChars.c -o obj\Debug\readFileByChars.o
g++.exe -LC:\Users\username\Documents\CodeBlocks\C\MISC -o bin\Debug\MISC.exe obj\Debug\readFileByChars.o readFileByChars.h.gch
readFileByChars.h.gch: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s))
Run Code Online (Sandbox Code Playgroud)
这是工具链目录:
我之前没有任何程序运行实例.我也有MINGW独立工作(不在环境变量中包含它的bin文件夹,不要在构建期间混淆代码块),但是对于代码块,我包括安装附带的预先打包的代码块.当我单击选项链接我的项目中的头文件时,项目将无法构建(但如果我不链接文件,我如何构建我的应用程序?).我重复这个项目是空的,我只有一个标题,只包含一个源文件.我在这里看到过关于此问题的其他类似问题,但他们的解决方案无效.帮助将不胜感激.谢谢.
linker-errors ×10
c++ ×8
c ×2
linker ×2
boost ×1
c++11 ×1
codeblocks ×1
header-files ×1
ld ×1
lnk2019 ×1
openssl ×1
templates ×1
ubuntu ×1