我正在尝试使用 Libelf 库来获取一些 elf 文件的信息。但我不断收到这些“未定义的引用[...]”。我从突触安装了 libelf(也尝试从网站获取),并且该库似乎安装正常。
我的代码:
#include <err.h>
#include <fcntl.h>
#include <sysexits.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <libelf.h>
int main(int argc, char * argv[]) {
Elf *elf_file;
Elf_Kind elf_kind_file;
int file_descriptor;
if((argc!=2))
printf("Argumento em formato nao esperado\n");
file_descriptor = open(argv[1], O_RDONLY, 0);
elf_file = elf_begin(file_descriptor, ELF_C_READ, NULL);
elf_kind_file = elf_kind(elf_file);
elf_end(elf_file);
close(file_descriptor);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是我从终端得到的信息(当前使用 Ubuntu 11.4):
gcc sample.c -o sample
/tmp/ccP7v2DT.o: In function `main':
sample.c:(.text+0x57): undefined reference to `elf_begin'
sample.c:(.text+0x67): undefined reference to `elf_kind'
sample.c:(.text+0x77): …Run Code Online (Sandbox Code Playgroud) 我正面临 boost unit_test 框架以及 autoconf 和 automake 的问题...
这是关于项目结构:
...
class FooSingleton {
protected:
FooSingleton() {}
private:
FooSingleton* _instance;
public:
virtual ~FooSingleton() {}
static FooSingleton* getInstance();
};
class FooFoo {
public:
FooFoo() {}
virtual uint32_t getSomeInt();
virtual ~FooFoo() {}
};
typedef boost::shared_ptr FooFooPtr_t;
...
Run Code Online (Sandbox Code Playgroud)
#include "com_foo.h"
Run Code Online (Sandbox Code Playgroud)
include_HEADERS = \
com_i_foo.h \
com_foo.h \
com_api.h \
$(NULL)
Run Code Online (Sandbox Code Playgroud)
PLATEFORM=LINUX64
DEBUG_OPTIONS = -g
DEFINE_OPTIONS=-D${PLATEFORM}
OPTIONS = -Wall -Werror -shared -O2 $(DEBUG_OPTIONS) $(DEFINE_OPTIONS)
COMMON_CXXFLAGS= ${OPTIONS} -I$(top_builddir)/include
ACLOCAL_AMFLAGS = …Run Code Online (Sandbox Code Playgroud) 我在使用向量时得到一个未定义的引用。
这是错误:
/tmp/ccYnTr05.o: In function `TourManager::addCity(City)':
tsp.cpp:(.text._ZN11TourManager7addCityE4City[TourManager::addCity(City)]+0x1c): undefined reference to `TourManager::destinationCities'
/tmp/ccYnTr05.o: In function `TourManager::getCity(int)':
tsp.cpp:(.text._ZN11TourManager7getCityEi[TourManager::getCity(int)]+0x14): undefined reference to `TourManager::destinationCities'
/tmp/ccYnTr05.o: In function `TourManager::numberOfCities()':
tsp.cpp:(.text._ZN11TourManager14numberOfCitiesEv[TourManager::numberOfCities()]+0x5): undefined reference to `TourManager::destinationCities'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
这是代码片段:
class TourManager
{
private:
static vector<City> destinationCities;
public:
static void addCity(City city)
{
destinationCities.push_back(city);
}
static City getCity(int index)
{
return (City)destinationCities.at(index);
}
static int numberOfCities()
{
return (int)destinationCities.size();
}
};
Run Code Online (Sandbox Code Playgroud)
我意识到向量尚未初始化为值,但向量不是动态分配内存的吗?我不知道如何解决这个未定义的参考问题?是向量的问题还是别的什么?谢谢。
我正在尝试在一个小的 c 程序中链接 gsl。
#include "stdlib.h"
#include "stdio.h"
#include "gsl/gsl_block_float.h"
#include "gsl/gsl_matrix_float.h"
int main(void)
{
gsl_matrix_float* m = gsl_matrix_float_alloc(2, 2);
gsl_matrix_float_fprintf(stdout, m, "%f");
}
Run Code Online (Sandbox Code Playgroud)
我正在编译gcc -lgsl -lgslcblas -lm program.c。我也尝试gcc $(pkg-config --cflags gsl) $(pkg-config --libs gsl) program.c过,与gsl-config. 在任何情况下,gcc 都会返回
/tmp/cc1wKgXm.o: In function `main':
program.c:(.text+0x13): undefined reference to `gsl_matrix_float_alloc'
program.c:(.text+0x32): undefined reference to `gsl_matrix_float_fprintf'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
objdump --syms /usr/lib/libgsl.so | grep gsl_matrix_float返回正确的符号,就像 grepping 我的标题一样。一切都在/usr/lib或/usr/include我做错了什么?
我正在尝试使用 boost 库 1.57 在 Linux x64 上编译我的 C++ 项目。
这个项目是用 scons 编译的,我在我的 Arch Linux 上成功编译了它,但这次在 Ubuntu 机器上失败了。
我添加-lboost_coroutine了链接标志,但错误“未定义引用”仍然存在。
/usr/bin/g++ -o build/gcc.release/app -pthread -g
build/gcc.release/src/han/unity/rpcx.o
-lpthread -lz -lboost_coroutine -lboost_context -lboost_date_time
build/gcc.release/src/han/unity/rpcx.o: In function `attributes':
/usr/local/include/boost/coroutine/attributes.hpp:31: undefined reference
to `boost::coroutines::stack_traits::default_size()'
Run Code Online (Sandbox Code Playgroud)
我注意到attributes.hpp 正是boost 协程头文件之一。我尝试使用 nm 来提升协程库,似乎没问题。
nm /usr/local/lib/libboost_coroutine.a | grep "default_size"
0000000000000170 T _ZN5boost10coroutines12stack_traits12default_sizeEv
Run Code Online (Sandbox Code Playgroud)
我搜索了这个错误的可能原因,大多数是关于链接器标志的顺序。在这种情况下,rpcx.o 依赖于 boost_coroutine,所以它出现在前面。
还有什么可能是原因?
我正在编译一个包含来自 pthread 库的互斥信号量的程序,但是当我使用 -lpthread 标志进行编译时,我收到了未定义的引用错误。
gcc -lpthread prodcon.c
/tmp/ccESOlOn.o: In function `producer':
prodcon.c:(.text+0x2e): undefined reference to `pthead_mutex_lock'
prodcon.c:(.text+0xd6): undefined reference to `pthead_mutex_unlock'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
互斥锁的语法如下:
pthread_mutex_t mutex1;
Run Code Online (Sandbox Code Playgroud)
是一个全局声明,以便它可以被多个线程使用。在函数中,我像这样调用互斥体:
pthead_mutex_lock(&mutex1);
pthead_mutex_unlock(&mutex1);
Run Code Online (Sandbox Code Playgroud)
但我收到编译器错误,我也尝试使用 -pthread 标志进行编译
gcc -pthread prodcon.c
/tmp/cc6wiQPR.o: In function `producer':
prodcon.c:(.text+0x2e): undefined reference to `pthead_mutex_lock'
prodcon.c:(.text+0xd6): undefined reference to `pthead_mutex_unlock'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我已经寻找答案,但我不知所措,并且希望能够帮助您弄清楚当我链接到包含互斥锁的库时为什么它有未定义的引用。
我尝试使用多种方法让它发挥作用,无论我不断得到什么:
/usr/local/include/vulkan/vulkan.hpp:2453: undefined reference to `vkCreateDebugUtilsMessengerEXT'
/usr/local/include/vulkan/vulkan.hpp:2548: undefined reference to `vkDestroyDebugUtilsMessengerEXT'
Run Code Online (Sandbox Code Playgroud)
这是我目前拥有的(希望这是足够的代码来诊断问题)
// destroy and create funcs
PFN_vkCreateDebugUtilsMessengerEXT pfnVkCreateDebugUtilsMessengerEXT;
PFN_vkDestroyDebugUtilsMessengerEXT pfnVkDestroyDebugUtilsMessengerEXT;
VKAPI_ATTR VkResult VKAPI_CALL vkCreateDebugUtilsMessengerEXT(VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT* pCreateInfo, const VkAllocationCallbacks* pAllocator, VkDebugUtilsMessengerEXT* pMessenger)
{
return pfnVkCreateDebugUtilsMessengerEXT(instance, pCreateInfo, pAllocator, pMessenger);
}
VKAPI_ATTR void VKAPI_CALL vkDestroyDebugUtilsMessengerEXT(VkInstance instance, VkDebugUtilsMessengerEXT messenger, VkAllocationCallbacks const * pAllocator)
{
return pfnVkDestroyDebugUtilsMessengerEXT(instance, messenger, pAllocator);
}
Run Code Online (Sandbox Code Playgroud)
// instance creation stuff here ...
createUniqueInstance(...);
//
// init and setup debug utils messenger
pfnVkCreateDebugUtilsMessengerEXT = reinterpret_cast<PFN_vkCreateDebugUtilsMessengerEXT>(
instance->getProcAddr("vkCreateDebugUtilsMessengerEXT"));
if (!pfnVkCreateDebugUtilsMessengerEXT) { …Run Code Online (Sandbox Code Playgroud) 我正在写一个H264解析器(没有OO),但我正在尝试使用一些模块来组织更好的东西.
我遇到了这个问题:
`CMakeFiles/server.dir/mainclass.cpp.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here
`CMakeFiles/server.dir/mainclass.cpp.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here
`CMakeFiles/server.dir/mainclass.cpp.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here
`CMakeFiles/server.dir/thRunAppl.cpp.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here
`CMakeFiles/server.dir/thRunAppl.cpp.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here
`CMakeFiles/server.dir/thRunAppl.cpp.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): first defined here
`CMakeFiles/server.dir/h.264parser.cpp.o:(.bss+0x0): multiple definition of `I_Macroblock_Modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x0): first defined here
`CMakeFiles/server.dir/h.264parser.cpp.o:(.bss+0x300): multiple definition of `P_and_SP_macroblock_modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x300): first defined here
`CMakeFiles/server.dir/h.264parser.cpp.o:(.bss+0x680): multiple definition of `B_Macroblock_Modes'
`CMakeFiles/server.dir/main.cpp.o:(.bss+0x680): …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用本教程安装C++ MongoDB 2.4驱动程序:http: //docs.mongodb.org/ecosystem/tutorial/getting-started-with-cpp-driver/
我使用scons成功下载并构建了驱动程序源代码.
当我尝试使用推荐的命令编译示例C++文件时:
$ g++ tutorial.cpp -pthread -lmongoclient -lboost_thread-mt -lboost_filesystem -lboost_program_options -lboost_system -o tutorial
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
/usr/lib/gcc/i686-linux-gnu/4.7/../../../../lib/libmongoclient.a(sock.o):
In function `mongo::SSLManager::setupPEM(std::string const&, std::string const&)':
(.text+0xc99): undefined reference to `SSL_CTX_use_certificate_chain_file'
/usr/lib/gcc/i686-linux-gnu/4.7/../../../../lib/libmongoclient.a(sock.o):
In function `mongo::SSLManager::setupPEM(std::string const&, std::string const&)':
(.text+0xceb): undefined reference to `SSL_CTX_set_default_passwd_cb_userdata'
Run Code Online (Sandbox Code Playgroud)
我检查过,我已经安装了这个软件包:libssl1.0.0 libssl-dev.
请帮我!
我想用C ++开发gui应用程序,发现SFML是一个不错的选择。幸运的是我在Linux上,所以SFML(2.4)已经安装在我的系统上。因此,我开始搜索一些教程,并找到了一个简单的窗口。但是,当我运行代码时,我得到一个错误,指出对sf::(我正在使用的函数)的未定义引用。这是代码
#include <SFML/Graphics.hpp>
int main(void)
{
sf::RenderWindow window(sf::VideoMode(640,480),"SFML working");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这是错误日志。
cd '/home/jasper/NetBeansProjects/SFML'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/home/jasper/NetBeansProjects/SFML'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/sfml
make[2]: Entering directory '/home/jasper/NetBeansProjects/SFML'
mkdir -p dist/Debug/GNU-Linux
g++ -o dist/Debug/GNU-Linux/sfml build/Debug/GNU-Linux/main.o
build/Debug/GNU-Linux/main.o: In function `main':
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::String::String(char const*, std::locale const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined reference to `sf::RenderWindow::RenderWindow(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
/home/jasper/NetBeansProjects/SFML/main.cpp:6: undefined …Run Code Online (Sandbox Code Playgroud)