标签: linker-errors

为什么模板函数指针出现链接器错误?

我有一个 EventMgr 类,它有一个模板函数来注册一个监听器。但是,当我注册一个监听器时,链接器给了我一个“错误 LNK2019:未解析的外部符号”。

开胃菜代码:

class EventMgr {

 template< class T, class EvenT>
 void RegisterListener(T* listener, int EventType, void (T::*MemFunc)(EvenT*) );
}
Run Code Online (Sandbox Code Playgroud)

SoundMgr(它是一个侦听器)尝试注册事件:

SoundMgr::SoundMgr(void)
{
  EventManager::GetInstance()->RegisterListener(this, 1, (&SoundMgr::handleBulletFired));
}
Run Code Online (Sandbox Code Playgroud)

我不确定为什么它不会链接。为什么找不到引用类型?

c++ templates function-pointers linker-errors

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

致命错误LNK1112:模块机器类型'X86'与目标机器类型'x64'冲突

我使用Visual Studio 2010 Premium.我有两个项目A和B,我尝试将它们编译为64位平台.
项目A输出项目B依赖的.dll和.lib文件.
我已经成功地将项目A编译到64位平台,但是当我编译项目BI时会出现以下错误:

mfcs100d.lib(nolib.obj):致命错误LNK1112:模块机器类型'X86'与目标机器类型'x64'冲突

可能是什么问题呢 ?我真的不知道这个mfcs100d.lib文件是什么.
我在项目A的dll文件上使用了"Dependency Walker",它似乎完全依赖于64位dll文件.另外,我进入了项目B(属性页 - >配置属性 - >链接器 - >高级)并确认'目标机'设置为"MachineX64".此外,在配置管理器上,平台设置为x64.

有人告诉我问题可能是这样的:

转到项目B(属性页 - >配置属性 - > C\C++ - >预处理器 - >预处理器定义)我有以下值:

WIN32  
_DEBUG  
_WINDOWS  
_AFXEXT  
Run Code Online (Sandbox Code Playgroud)

那是真的相关吗?我应该更换'WIN32'值吗?如果是的话,怎么样?我真的不明白这些定义的含义以及如何改变它们.

编辑:我刚刚意识到它可能完全不相关.这些只是预处理器的定义,例如可以通过C++ #define命令确定的定义.但我可能是错的.

64-bit preprocessor linker-errors visual-studio-2010

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

模板构造函数中的C++链接器错误:"未解析的外部符号"

我试图用C++编写一个模板类并得到这个奇怪的链接器错误而无法找出原因,请让我知道这有什么问题!

以下是我在Visula C++ 2010中收到的错误消息.

1>------ Rebuild All started: Project: FlashEmulatorTemplates, Configuration: Debug Win32 ------
1>  main.cpp
1>  emulator.cpp
1>  Generating Code...
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall flash_emulator<char>::flash_emulator<char>(char const *,struct FLASH_PROPERTIES *)" (??0?$flash_emulator@D@@QAE@PBDPAUFLASH_PROPERTIES@@@Z) referenced in function _main
1>C:\Projects\FlashEmulator_templates\VS\FlashEmulatorTemplates\Debug\FlashEmulatorTemplates.exe : fatal error LNK1120: 1 unresolved externals
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)

g ++中的错误消息

main.cpp: In function âint main()â:
main.cpp:8: warning: deprecated conversion from string constant to âchar*â
/tmp/ccOJ8koe.o: In function `main':
main.cpp:(.text+0x21): undefined …
Run Code Online (Sandbox Code Playgroud)

c++ templates linker-errors

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

链接错误2019用于编程分配

1>Main.obj : error LNK2019: unresolved external symbol "void __cdecl createVideoList(class                          std::basic_ifstream<char,struct std::char_traits<char> > &,class Video &)" (?createVideoList@@YAXAAV?$basic_ifstream@DU?$char_traits@D@std@@@std@@AAVVideo@@@Z) referenced in function _main
1>c:\users\******\documents\visual studio 2010\Projects\Programming Assignment 4\Debug\Programming Assignment 4.exe : fatal error LNK1120: 1 unresolved externals
Run Code Online (Sandbox Code Playgroud)

我正在编写一个编程作业,我在尝试编译时遇到了这个链接错误2019.它引用了createVideoList,这些是与我相关的代码行:

#include <iostream>
#include <fstream>
#include <string>
#include "Video.h"
using namespace std;

void createVideoList(ifstream& infile, Video videoArray);

int main()
{
...
createVideoList(inputfile, videoArray[50]);
}

void createVideoList(ifstream& ifile, Video videoArray[50])
{
string title;
string star1;
string star2;
string producer;
string director;
string productionCo;
int inStock;
int …
Run Code Online (Sandbox Code Playgroud)

c++ linker-errors lnk2019

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

C编程 - "文件中引用的未定义符号"

我正在尝试编写一个程序来估算pi.它基本上取0.00和1.00之间的随机点,并将它们与圆的界限进行比较,圆内点与总点的比率应接近pi(非常快速的解释,规范深入更多).

但是,在使用gcc进行编译时出现以下错误:

Undefined                       first referenced
symbol                          in file
pow                             /var/tmp//cc6gSbfE.o
ld: fatal: symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

发生了什么事?我以前从未见过这个错误,我不知道它为什么会出现.这是我的代码(虽然我没有完全测试它,因为我无法通过错误):

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
    float x, y;
    float coordSquared;
    float coordRoot;
    float ratio;
    int n;
    int count;
    int i;

    printf("Enter number of points: ");
    scanf("%d", &n);

    srand(time(0));

    for (i = 0; i < n; i++) {
        x = rand();
        y = rand();

        coordSquared = pow(x, 2) + pow(y, …
Run Code Online (Sandbox Code Playgroud)

c linker-errors undefined-reference

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

架构i386的未定义符号:"_ OBJC_CLASS _ $ _ GDataDateTime",引自:

我曾在谷歌日历工作过.现在我从这个链接下载示例代码:

"http://code.google.com/p/iphone-gcal/". 
Run Code Online (Sandbox Code Playgroud)

但是在这段代码中,缺少一些Gdata代码.所以我已经实现了该代码,但我也得到了以下错误.请一些人帮我解决这个错误.

Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_GDataDateTime", referenced from:
      objc-class-ref in RootViewController.o
      objc-class-ref in EditingViewController.o
  "_OBJC_CLASS_$_GDataEntryCalendarEvent", referenced from:
      objc-class-ref in EditingViewController.o
  "_OBJC_CLASS_$_GDataQueryCalendar", referenced from:
      objc-class-ref in RootViewController.o
  "_OBJC_CLASS_$_GDataServiceGoogleCalendar", referenced from:
      objc-class-ref in RootViewController.o
  "_OBJC_CLASS_$_GDataWhen", referenced from:
      objc-class-ref in RootViewController.o
      objc-class-ref in EditingViewController.o
  "_OBJC_CLASS_$_GDataWhere", referenced from:
      objc-class-ref in EditingViewController.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch google-calendar-api linker-errors ios

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

C静态库无法与librt链接

我要创建一个静态库(它不是创建一个动态的一个选项),我有在使用这个静态库中的函数timer_createtime.h例如是这样的:

somelib.h:

#include <time.h>

int do_something(void);
Run Code Online (Sandbox Code Playgroud)

somelib.c:

int do_something(void){
        timer_t timer;
        struct sigevent sevp;
        sevp.sigev_notify = SIGEV_SIGNAL;
        sevp.sigev_signo = SIGRTMIN;
        sevp.sigev_value.sival_ptr = NULL;
        int ret = timer_create(CLOCK_MONOTONIC, &sevp, &timer);
        timer_delete(timer);
        return 0;
}
Run Code Online (Sandbox Code Playgroud)

代码实际上是没有意义的,只是在那里有必要链接librt来说明我的问题,如下:

编译somelib.c后:

gcc -c -o somelib.o somelib.c -lrt
Run Code Online (Sandbox Code Playgroud)

并创建静态库:

ar rcs somelib.a somelib.o
Run Code Online (Sandbox Code Playgroud)

链接它时出现以下错误:

gcc -o someexec someexec.c -lrt ./somelib.a
Run Code Online (Sandbox Code Playgroud)

收益:

somelib.c:(.text+0x30): undefined reference to `timer_create'
somelib.c:(.text+0x44): undefined reference to `timer_destroy'
Run Code Online (Sandbox Code Playgroud)

这是我的问题的最小例子.我不确定是否可以解决这个问题,因为我的理解是,静态库必须知道librt在创建时的位置,因为它是动态的,所以如果没有链接到静态则不可能librt的版本.我仍然不经常使用静态库,所以我想知道是否有办法做这样的事情.

编译器版本:gcc 4.8.1没有设置其他标志.

c automake gcc linker-errors unix-ar

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

链接:致命错误 lnk1181:无法打开输入文件 'id=2.obj'

我正在尝试使用 VS2015 x64 本机工具命令提示符在我的 Windows 10 中编译 cudamat。我已经安装了 Cuda 工具包 8 以及带有 MSVC 编译器的 Visual Studio 2015。下载 cudamat 后,我​​在该目录中给出了以下命令:

python setup.py 安装

当它尝试构建 cudamat.libcudamat 扩展时,链接器出现以下错误:

致命错误 lnk1181:无法打开输入文件 'id=2.obj'

错误:命令“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0\bin\nvcc.exe”失败,退出状态为 2

有人可以帮助我吗?

python linker-errors visual-studio-2015 cudamat

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

用于编译 HDF5 的 CMakelists.txt?

我正在尝试编译一个简单的程序来读取 HDF5 文件。代码使用 h5c++ 正确编译。但是我需要一个相同的 cmakelists.txt

读取数据文件

#include <iostream>
#include "H5Cpp.h"
#ifndef H5_NO_NAMESPACE
    using namespace H5;
#endif
const H5std_string FILE_NAME( "testfile.h5" );

int main (void)
{
    H5File openFile( FILE_NAME, H5F_ACC_RDONLY );
}
Run Code Online (Sandbox Code Playgroud)

我为它尝试了一个 cmakelists 但它没有用。它给出了“未定义的错误”

readdata.cpp:(.text+0x1d): undefined reference to `H5::FileAccPropList::DEFAULT'
readdata.cpp:(.text+0x24): undefined reference to `H5::FileCreatPropList::DEFAULT'
readdata.cpp:(.text+0x38): undefined reference to `H5check_version'
readdata.cpp:(.text+0x54): undefined reference to `H5::H5File::H5File(std::__cxx11::basic_string<char,     std::char_traits<char>, std::allocator<char> > const&, unsigned int, H5::FileCreatPropList const&, H5::FileAccPropList const&)'
readdata.cpp:(.text+0x60): undefined reference to `H5::H5File::~H5File()'
Run Code Online (Sandbox Code Playgroud)

CMakelists.txt

cmake_minimum_required(VERSION 3.1.0) 
PROJECT (readhdf5)

find_package(HDF5 REQUIRED)
include_directories(${HDF5_INCLUDE_DIRS})

add_executable( readdata …
Run Code Online (Sandbox Code Playgroud)

c++ cmake hdf5 linker-errors

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

从Yosemite升级到High Sierra后出现pycurl链接错误

我刚从Yosemite升级到High Sierra,效果很好,唯一的例外是我在pycurl中有一个bug.

    import pycurl
ImportError: No module named pycurl
Run Code Online (Sandbox Code Playgroud)

所以我做了

pip uninstall pycurl
Run Code Online (Sandbox Code Playgroud)

pip install --no-cache-dir --compile pycurl
Run Code Online (Sandbox Code Playgroud)

但现在它导致了一个铿锵声

    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.10-x86_64-2.7/src/docstrings.o build/temp.macosx-10.10-x86_64-2.7/src/easy.o build/temp.macosx-10.10-x86_64-2.7/src/module.o build/temp.macosx-10.10-x86_64-2.7/src/multi.o build/temp.macosx-10.10-x86_64-2.7/src/oscompat.o build/temp.macosx-10.10-x86_64-2.7/src/pythoncompat.o build/temp.macosx-10.10-x86_64-2.7/src/share.o build/temp.macosx-10.10-x86_64-2.7/src/stringcompat.o build/temp.macosx-10.10-x86_64-2.7/src/threadsupport.o -L/usr/local/lib -L/usr/local/opt/openssl/lib -L/usr/local/opt/sqlite/lib -lssl3 -lcurl -o build/lib.macosx-10.10-x86_64-2.7/pycurl.so
ld: library not found for -lssl3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1

----------------------------------------
Command "/usr/local/opt/python/bin/python2.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/5h/h0hwdpps0cd_v2k_m652wwzm0000gq/T/pip-build-1rx5q1/pycurl/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, …
Run Code Online (Sandbox Code Playgroud)

python linker-errors

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