标签: undefined-reference

c ++静态库引用另一个库的链接器错误

我对c ++很新,我在调试链接器错误时遇到问题.我正在使用wxDev-c ++和g ++编译器.我创建了一个静态库,我将其链接到一个基本项目.该库最初不包含对外部头文件或库的引用,它只是一些简单的测试函数,将2个双精度数组合在一起并返回值.这与链接到测试项目时工作正常.但是我现在正试图将FTP合并到该库中,现在我正在收到链接器错误.

目前测试功能只是试图访问相同的简单添加功能进行测试,我甚至没有调用FTP功能,因为我只是想让测试项目正确编译.

库代码:

DaFTPLib.h:

#ifndef WAVE_H
#define WAVE_H
#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include <wx/wx.h>
#else
#include <wx/wxprec.h>
#endif

#include <wx/protocol/ftp.h>

namespace Wave
{
    class DaFTP
    {
        public:
        DaFTP(char *url, char *login, char *password);
        ~DaFTP();
        const int Download(char* fileName);
        static const void DownloadNCWD(char *url, char *fileName, char *login, char *password);
        static const void DownloadLAMP();
        static double FuncA(double a, double b);
        static double FuncB(double a, double b);

        private:
        char* url, login, password;
        wxFTP ftp;
    };
} …
Run Code Online (Sandbox Code Playgroud)

c++ linker static-libraries undefined-reference

5
推荐指数
1
解决办法
2769
查看次数

“未定义引用‘IMG_Load’”CodeBlocks 和 SDL_Image 错误

我正在通过 Lazy Foo 的教程学习 SDL,但我无法继续进行,因为 IMG_Load 似乎不起作用。我尝试按照他说的那样进行设置,但它不起作用。我将所有包含文件放入 include 文件夹中,将所有 lib 文件放入 lib 文件夹中。我发现lib文件夹中有x86和x64文件夹。当我尝试 x64 时(因为我有一个 64 位系统),一切都工作正常,CodeBlocks 甚至告诉我建议(比如当我写“img”时,它显示了一个建议“IMG_Load”(这意味着库已初始化?)) ,但是当我编译代码时,会发生这种情况: http: //puu.sh/3Eqa5.png。当我尝试使用 x86 版本时,出现完全相同的错误。

我在网上查了一下,只找到了一些线索,但大多数都被放弃了。我最接近回答我的问题的是: http: //www.dreamincode.net/forums/topic/118299-sdl-image-error-sdl/,但这家伙通过下载一个Linux可以使用的问题解决了他的问题,不是Windows。}

我运行的是 Windows 7 64 位、CodeBlocks 12.11、SDL 1.2.15 和 SDL_Image 1.2.12。

我真的不知道问题是什么!

c sdl sdl-image codeblocks undefined-reference

5
推荐指数
1
解决办法
1万
查看次数

动态加载类的 dynamic_cast 导致未定义的引用

我有一个 C++ 类,它的定义将在运行时通过dlopen. 我无法让它链接。我收到错误消息,说存在“对 typeinfo 的未定义引用”。

代码的相关部分如下所示:

class Interface { ... };
class Impl : public Interface { ... };

Interface *Create() { ... }

// Load shared object around here

Impl *impl = dynamic_cast<Impl*>(Create()); // Undefined reference to typeinfo
Run Code Online (Sandbox Code Playgroud)

我尝试添加-rdynamic到我的链接器命令中,但这似乎没有改变任何东西。我能做些什么吗?

由于我看到很多关于未定义虚函数导致的相同错误消息的问题,我应该提到我确定这不是我的问题。

另外我应该补充一点,我确定这与dynamic_cast有关,因为如果我用正常(Impl*)的转换替换dynamic_cast,代码链接正确。

c++ linker dynamic-cast dlopen undefined-reference

5
推荐指数
0
解决办法
585
查看次数

未定义的log10函数引用

我正在使用Eclipse Kepler进行构建,并已包含在内math.h.但是,我收到了一个错误

'对log10的未定义引用'.

还有类型uint8_tunit32_t尚未解决.我既包括stdint.hinttypes.h,只是可以肯定的,但没有成功.有人可以帮忙吗?

c undefined-reference

5
推荐指数
1
解决办法
1万
查看次数

yaml-cpp 的编译器错误 - 未定义对 `YAML::detail::node_data::convert_to_map` 的引用

这是完整的日志:

/tmp/ccCvErNZ.o: In function `YAML::detail::node& YAML::detail::node_data::get<std::string>(std::string const&, std::shared_ptr<YAML::detail::memory_holder>)':
cricket.cpp:(.text._ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE[_ZN4YAML6detail9node_data3getISsEERNS0_4nodeERKT_St10shared_ptrINS0_13memory_holderEE]+0x94): undefined reference to `YAML::detail::node_data::convert_to_map(std::shared_ptr<YAML::detail::memory_holder>)'
collect2: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我试图编译的代码很简单

#include <iostream>
#include <yaml-cpp/yaml.h>

using namespace std;

int main() {
    YAML::Node test = YAML::LoadFile("test.yaml");
    if (test["date"]) {
      cout << "HELLO";
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我使用的 YAML 是来自http://www.yaml.org/start.html的示例

如果我只是尝试加载 YAML,它加载得很好。但是,如果我尝试访问任何数据,则会出现相同的错误。所以这不是链接问题。

编辑:我可以做这样的事情cout << test,并cout << test.type()和其他功能。我认为问题在于使用基于字符串的映射来访问内部节点。

c++ yaml undefined-reference yaml-cpp

5
推荐指数
1
解决办法
8306
查看次数

对“__gnu_Unwind_Find_exidx”的未定义引用

我的 NDK 项目仅在以下情况下构建成功

APP_ABI :=  armeabi armeabi-v7a
Run Code Online (Sandbox Code Playgroud)

当我启用arm64-v8aApplication.mk,例如:

APP_ABI :=  armeabi armeabi-v7a arm64-v8a
Run Code Online (Sandbox Code Playgroud)

该项目将构建失败并显示错误

对 `__gnu_Unwind_Find_exidx 的未定义引用

我是 android NDK 的新手。

代码截图: 在此输入图像描述

android undefined-reference android-ndk

5
推荐指数
0
解决办法
257
查看次数

获取对 std::thread::_M_start_thread 的未定义引用

我正在构建一个应用程序,该应用程序使用我从源代码构建的 3rd 方库 (Box2D-MT)。链接时,我收到此未定义的参考错误:

b2Threading.cpp:(.text._ZNSt6threadC2IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_[_ZNSt6threadC5IM12b2ThreadPoolFviEJPS1_iEEEOT_DpOT0_]+0xa4): 
undefined reference to 'std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>, void (*)())'
Run Code Online (Sandbox Code Playgroud)

我正在用 g++ 构建并链接

-lBox2D -lpthread -lrt -ldl -lstdc++
Run Code Online (Sandbox Code Playgroud)

另外,我正在编译

-std=c++11
Run Code Online (Sandbox Code Playgroud)

查看 libstdc++.a 我可以看到类似的这个符号存在(它是“T”):

nm -C /usr/lib/gcc/x86_64-linux-gnu/4.9.2/libstdc++.a | grep _M_start_thread
0000000000000000 T std::thread::_M_start_thread(std::shared_ptr<std::thread::_Impl_base>)
Run Code Online (Sandbox Code Playgroud)

但是这个重载不需要第二个参数。

我已经在所有互联网上搜索过类似的东西,但之前似乎没有人遇到过这个问题(在任何情况下)。

关于我为什么会收到此错误以及如何解决它的任何提示?

c++ multithreading g++ ld undefined-reference

5
推荐指数
1
解决办法
8319
查看次数

如何从 OpenSSL 中的 perl 脚本生成程序集文件

在 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 …

c openssl powerpc undefined-reference

5
推荐指数
1
解决办法
1932
查看次数

Catch2 - 未定义的引用

我正在使用 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)

c++ testing undefined-reference catch-unit-test

5
推荐指数
1
解决办法
7347
查看次数

Google使用SetUpTestCase静态变量测试未定义的引用

我正在编写一个测试用例,它将有一个SetUpTestCase()分配共享资源的方法,尽管我收到的是未定义的引用链接器错误.

class ParsingEventsTest: public ::testing::Test {
    protected:

        static xml eventXml;

        static void SetUpTestCase() {
            ManagedObjectManagerSingleton::GET_SINGLETON().initializeTestEnvironment(PATH_TO_FILE);
            eventXml= *ManagerSingleton::GET_SINGLETON().parse(PATH_TO_INPUT_FILES);
        }

        virtual void SetUp() {}
        virtual void TearDown() {}
};
Run Code Online (Sandbox Code Playgroud)

这会导致:

../test/ParsingEventsTest.o: In function `ParsingEventsTest::SetUpTestCase()':
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xa1): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xb0): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xbd): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xc2): undefined reference to `ParsingEventsTest::eventXml'
ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xce): undefined reference to `ParsingEventsTest::eventXml'
../test/ParsingEventsTest.o:ParsingEventsTest.cpp:(.text._ZN17ParsingEventsTest13SetUpTestCaseEv[ParsingEventsTest::SetUpTestCase()]+0xdd): more undefined references to `ParsingEventsTest::eventXml' follow
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

编辑:

这也适用于非常简单的例如int分配

class ParsingEventsTest: public ::testing::Test { …
Run Code Online (Sandbox Code Playgroud)

c++ googletest undefined-reference testcase

4
推荐指数
1
解决办法
6587
查看次数