我有一个用MinGW构建的静态库,我试图从Qt应用程序链接到该库.我不断收到由库中的一个目标文件引起的链接器错误.这个文件实际上声明了几个Boost头文件,一个用于使用shared_ptr,另一个用于使我可以使类不可复制.我相信使用这个提升功能是导致问题的原因,但我不知道为什么.如果我在Qt应用程序中注释掉使用文件中定义的类的类,那么Qt应用程序链接正常.这是输出的错误部分:
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x10a):未定义引用`__gxx_personality_sj0'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x12f):未定义引用`_Unwind_SjLj_Register'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x203):未定义引用`_Unwind_SjLj_Resume'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x20e):未定义引用`_Unwind_SjLj_Unregister'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x226):未定义引用`__gxx_personality_sj0'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x24b):未定义引用`_Unwind_SjLj_Register'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x31f):未定义引用`_Unwind_SjLj_Resume'
C:\ blah\build\windows\mingw\libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(.text + 0x32a):未定义引用`_Unwind_SjLj_Unregister'
C:\等等\建立\ WINDOWS\MinGW的\ libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(文字$ _ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_ [升压::详细:: SHARED_COUNT :: SHARED_COUNT(富:: foo_SomeClassImpl*)] + 0xc):未定义对`__gxx_personality_sj0'的引用
C:\等等\建立\ WINDOWS\MinGW的\ libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(文字$ _ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_ [升压::详细:: SHARED_COUNT :: SHARED_COUNT(富:: foo_SomeClassImpl*)] + 0x31):对`_Unwind_SjLj_Register'的未定义引用
C:\等等\建立\ WINDOWS\MinGW的\ libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp :(文字$ _ZN5boost6detail12shared_countC1IN3foo25foo_SomeClassImplEEEPT_ [升压::详细:: SHARED_COUNT :: SHARED_COUNT(富:: foo_SomeClassImpl*)] + 0xfb):对`_Unwind_SjLj_Resume'的未定义引用
C:\等等\建立\ WINDOWS\MinGW的\ libfoo.a(foo_ctis.cpp.obj):foo_ctis.cpp …
嗨,
我编译了一个CUDA共享库,但无法将其与使用它的主程序链接.我用gcc编译主程序.
代码:
simplemain.c
#include <stdio.h>
#include <stdlib.h>
void fcudadriver();
int main()
{
printf("Main \n");
fcudadriver();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
test.cu
__global__ void fcuda()
{
}
void fcudadriver()
{
fcuda<<<1,1>>>();
}
Run Code Online (Sandbox Code Playgroud)
我编译test.cu为 - >它的工作原理
nvcc --compiler-options '-fPIC' -o libtest.so --shared test.cu
Run Code Online (Sandbox Code Playgroud)
我编译simplemain.c为--->它给出错误:(
gcc simplemain.c -L. -ltest
/tmp/ccHnB4Vh.o:simplemain.c:function main: error: undefined reference to 'fcudadriver'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) Recently I learned the beautiful language D, which is so more plastic and helps yourself writing stable fast programs. But its not popular... because few code written on D and so more on C and C++. Therefore after I read the book of Andrei Alexanderscu where author very superficially described question about linking of D library to C++ code, I tried learn it myself and written some code on D where defined function that returns an instance of CompleteAutomata class …
我发现了未定义引用的原因.我检查了我的.o文件中的符号,但它们只是丢失了.只是不在那里.没有明显的理由.我检查了妥协.o文件的来源,但一切似乎都没问题.我认为它可能是那些讨厌的#ifdef ... #endif块之一,狡猾地隐藏在代码的行中,像熊陷阱,等待它的受害者.但我找不到任何东西.将一些函数定义移动到文件的最后并将它们封装在#ifdef ... #endif适合Linux的块中之后,这些符号神奇地出现了,一切都很好.感谢您的时间.
过时了,不要读.
我最近被分配到一个大项目,我的工作是让它在Linux平台上运行.不幸的是,在我之前编写整个项目的程序员做了一个非常糟糕的工作,通过将文件
B3D_Base.h(几乎每个标题都包含在内)创建#included到项目中的几乎每个头文件和源文件中创建了大量的循环依赖(创建了170多个文件#include "B3D_Base.h"线).这在Windows和Linux上编译期间没有引起任何问题.但是,这会在Linux上的链接阶段导致大量"未定义的引用"错误,即使所有目标文件和库都已链接.
ld在链接期间意识到通过所有目标文件的单次迭代的限制,我问:
有没有办法强制ld通过对象和库进行多次迭代,可能解决所有700多个未定义的引用错误,或者是我唯一的机会实际链接项目只是将所有#include "B3D_Base.h"行替换为正确的包含到所需的标题?
这是一个我应该在Linux上运行的混乱的例子:
有一个头文件B3D_Base.h,向其中包括B3D_Loading3.h,含有类B3D_LOADING3.文件B3D_Loading3.cpp仅B3D_Base.h包含和Base中未包含的内存管理器类.B3D_LOADING3 g_Loading3;声明一个实例B3D_Base.h并初始化+在项目的许多其他部分中使用.一切都编译得很好,但是当谈到链接时,我会遇到很多'undefined reference to g_Loading3'错误.还有更多这样的错误,抱怨对类实例和函数的未定义引用.这么干净的代码.
我将提供一个SSCCE示例,正如kfsone所要求的:
B3D_Base.h
... (many other includes)
#include "B3D_Loading3.h"
extern B3D_LOADING3 g_Loading3;
... (includes go on)
Run Code Online (Sandbox Code Playgroud)
B3D_Loading3.h/B3D_Loading.cpp
a full definition of class B3D_LOADING3, but no real declaration of g_Loading3 …Run Code Online (Sandbox Code Playgroud) 我有以下简单的程序,我试图在linux ubuntu中编译.
Main.c:
#include <stdio.h>
#include "Person.h"
int main()
{
struct Person1 p1 = Person1_Constructor(10, 1000);
}
Run Code Online (Sandbox Code Playgroud)
Person.c:
#include <stdio.h>
#include "Person.h"
struct Person1 Person1_Constructor(const int age, const int salary)
{
struct Person1 p;
p.age = age;
p.salary = salary;
return p;
};
Run Code Online (Sandbox Code Playgroud)
Person.h:
struct Person1
{
int age, salary;
};
struct Person1 Person1_Constructor(const int age, const int salary);
Run Code Online (Sandbox Code Playgroud)
为什么我会收到以下错误?
/tmp/ccCGDJ1k.o: In function `main':
Main.c:(.text+0x2a): undefined reference to `Person1_Constructor'
collect2: error: ld returned 1 exit …Run Code Online (Sandbox Code Playgroud) 我有以下设置(希望这不是一个例子):
啊
typedef std::map<unsigned int, float> MyClass;
extern MyClass inst;
Run Code Online (Sandbox Code Playgroud)
A.cpp
MyClass inst;
Run Code Online (Sandbox Code Playgroud)
BH
#include <A.h>
void foo();
Run Code Online (Sandbox Code Playgroud)
B.cpp
#include <B.h>
void foo {
inst.myClassFunc();
}
Run Code Online (Sandbox Code Playgroud)
现在,当我使用inst时,B.cpp我得到了undefined reference to inst.
有关如何解决此问题的任何想法?
我正在尝试安装netgen(从源代码构建).因此需要Togl,我通过它安装它
sudo apt-get install libtogl1 libtogl-dev
Run Code Online (Sandbox Code Playgroud)
输入'make'时,我收到以下错误消息:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libTogl.so: undefined reference to `Tk_InitStubs'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libTogl.so: undefined reference to `tkStubsPtr'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libTogl.so: undefined reference to `Tcl_InitStubs'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libTogl.so: undefined reference to `tclStubsPtr'
Run Code Online (Sandbox Code Playgroud)
也许Togl没有正确安装.这是32位64位发行吗?我该怎么做才能解决这个问题?
我的 NDK 项目仅在以下情况下构建成功
APP_ABI := armeabi armeabi-v7a
Run Code Online (Sandbox Code Playgroud)
当我启用arm64-v8a时Application.mk,例如:
APP_ABI := armeabi armeabi-v7a arm64-v8a
Run Code Online (Sandbox Code Playgroud)
该项目将构建失败并显示错误
对 `__gnu_Unwind_Find_exidx 的未定义引用
我是 android NDK 的新手。
在 OpenSSL(版本 1.1.0e)的开源代码中,我看到一些函数定义是由文件夹中存在的 perl 文件生成的。在加密货币内每个文件夹中的 build.info 文件中,他们编写了一些行以从相应的 .pl 生成 .s。
例如,对于aes_p8_set_encrypt_key在 中生成crypto/aes/build.info:
GENERATE[aesp8-ppc.s]=asm/aesp8-ppc.pl $(PERLASM_SCHEME)
Run Code Online (Sandbox Code Playgroud)
用于OPENSSL_madd300_probe生成crypto/build.info:
GENERATE[ppccpuid.s]=ppccpuid.pl $(PERLASM_SCHEME)
Run Code Online (Sandbox Code Playgroud)
并且在主Makefile(生成的makefile)中,有如下几行:
crypto/aes/aes-x86_64.o: crypto/aes/aes-x86_64.s
$(CC) -I. -Icrypto/include -Iinclude $(CFLAGS) $(LIB_CFLAGS) -MMD -MF crypto/aes/aes-x86_64.d.tmp -MT $@ -c -o $@ crypto/aes/aes-x86_64.s
@touch crypto/aes/aes-x86_64.d.tmp
@if cmp crypto/aes/aes-x86_64.d.tmp crypto/aes/aes-x86_64.d > /dev/null 2> /dev/null; then \
rm -f crypto/aes/aes-x86_64.d.tmp; \
else \
mv crypto/aes/aes-x86_64.d.tmp crypto/aes/aes-x86_64.d; \
fi
Run Code Online (Sandbox Code Playgroud)
接下来是:
crypto/aes/aes-x86_64.s: crypto/aes/asm/aes-x86_64.pl
CC="$(CC)" $(PERL) crypto/aes/asm/aes-x86_64.pl $(PERLASM_SCHEME) $@
Run Code Online (Sandbox Code Playgroud)
谁能解释一下 .s 是如何从 .pl 文件生成的?我需要将它们添加到项目内的 Makefile …
我正在使用 Catch2 作为库来测试我的项目。我遵循了 Catch 文档中的每个步骤,但是当我运行测试时,出现以下错误:
CMakeFiles/tests.dir/tests/IntegerIntervalTest.cpp.o: in function "____C_A_T_C_H____T_E_S_T____0()":
/home/davide/cpp-project/tests/IntegerIntervalTest.cpp:8: undefined reference to "domain::IntegerAbstractInterval<int, int>::IntegerAbstractInterval(int, int)"
对于测试“类”中的每个方法调用,都会重复此错误。
CMake 列表:
PROJECT(cpp_project)
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG(-std=c++14 COMPILER_SUPPORTS_CXX14)
IF (COMPILER_SUPPORTS_CXX14)
ADD_COMPILE_OPTIONS("-std=c++14")
ELSE ()
MESSAGE(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++14 support.")
ENDIF ()
set(BASE_SRCS src/Bound.cpp src/Bound.hpp src/Infinity.cpp src/Infinity.hpp src/AbstractInterval.cpp src/AbstractInterval.hpp
src/UndefinedOperationException.hpp src/IntegerAbstractInterval.cpp src/IntegerAbstractInterval.hpp src/FloatingPointAbstractInterval.cpp
src/FloatingPointAbstractInterval.hpp)
ADD_COMPILE_OPTIONS("-Wall" "-Wextra" "-Wpedantic" "-Werror" )
ADD_LIBRARY(cpp-project ${BASE_SRCS})
INCLUDE_DIRECTORIES(libs/variant/include)
set(EXECUTABLE_OUTPUT_PATH bin)
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch)
add_library(Catch INTERFACE)
target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
set(TEST_SRCS tests/InfinityTest.cpp tests/IntegerIntervalTest.cpp)
add_executable(tests ${BASE_SRCS} ${TEST_SRCS})
target_link_libraries(tests Catch)
Run Code Online (Sandbox Code Playgroud)
这是测试文件IntegerIntervalTest.cpp:
#include …Run Code Online (Sandbox Code Playgroud)