标签: linker-errors

C++:纯虚拟赋值运算符

为什么如果我们在基类中有纯虚拟赋值运算符,那么我们在派生类上实现该运算符,它会在基类上给出链接器错误?

目前我在http://support.microsoft.com/kb/130486上只有以下说明,它说该行为是设计的,因为正常的继承规则不适用.

我不清楚,为什么它会通过设计产生链接器错误?有人可以给我更明确的解释吗?

编辑:添加了我发生错误的简化代码:

class __declspec(dllexport) BaseClass {
public:
    int memberA;
    virtual BaseClass& operator=(const BaseClass& rhs) = 0;
};

class __declspec(dllexport) DerivedClass : public BaseClass {
public:
    int memberB;
    DerivedClass():memberB(0) {}
    virtual BaseClass& operator=(const BaseClass& rhs) {
        this->memberA = rhs.memberA;
        this->memberB = 1;
        return *this;
    }
};

int main(void)
{
    DerivedClass d1;
    DerivedClass d2;

    BaseClass* bd1 = &d1;
    BaseClass* bd2 = &d2;

    *bd1 = *bd2;
}
Run Code Online (Sandbox Code Playgroud)

如果没有 __declspec(dllexport)和/或没有基类上的纯虚拟运算符=声明,代码将编译时没有错误.

在没有__declspec(dllexport) …

c++ linker-errors pure-virtual operator-keyword

6
推荐指数
2
解决办法
4192
查看次数

dyld:找不到符号:错误如何解决此问题

我有以下代码(如下所示),我用它NSURLConnection来连接和解析响应字符串.但是我收到以下错误:

dyld: Symbol not found: _CFXMLNodeGetInfoPtr
  Referenced from: /System/Library/Frameworks/Security.framework/Versions/A/Security
  Expected in: /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
 in /System/Library/Frameworks/Security.framework/Versions/A/Security
Run Code Online (Sandbox Code Playgroud)

我一直在努力解决这个问题而不能解决这个错误.

我已经导入了json.h和ASIHTTPRequest.h,所有这些文件仍然没有修复错误.

@implementation Websample1ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    dataWebService = [[NSMutableData data] retain];
    NSMutableURLRequest *request = [[NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://www.googleapis.com/customsearch/v1?key=AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx=017576662512468239146:omuauf_lfve&q=lectures&callback=handleResponse"]]retain];    

    NSURLConnection *myConnection = [NSURLConnection connectionWithRequest:request delegate:self];
    [myConnection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response 
{
    [dataWebService setLength:0];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [dataWebService appendData:data];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection 
{
    NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
    NSLog(@"Response: %@",responseString);
    [responseString release];
    [dataWebService release]; …
Run Code Online (Sandbox Code Playgroud)

iphone xcode objective-c linker-errors

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

"错误LNK2001:未解析的外部符号"

我在VC++ 2008中的程序有问题.当我编译它时,会列出以下错误.我花了很多时间在groups.google.com上查找原因,但没有评论帮助我.有人知道问题是什么吗?谢谢.

error LNK2001: unresolved external symbol "long rfl_xref_id" (?rfl_xref_id@@3JA)
error LNK2001: unresolved external symbol "struct obj_name * pat_objname_list" (?pat_objname_list@@3PAUobj_name@@A)
error LNK2001: unresolved external symbol "struct obj_name * pat_recall_objname_list" (?pat_recall_objname_list@@3PAUobj_name@@A)
error LNK2001: unresolved external symbol "wchar_t * rfl_unresolved_xref_tag" (?rfl_unresolved_xref_tag@@3PA_WA)
error LNK2001: unresolved external symbol "struct ref_pages * rfl_pages" (?rfl_pages@@3PAUref_pages@@A)
error LNK2001: unresolved external symbol "short rfl_use_regen_id" (?rfl_use_regen_id@@3FA)
error LNK2001: unresolved external symbol "long rfl_regen_id" (?rfl_regen_id@@3JA)
error LNK2001: unresolved external symbol "unsigned short rfl_list_status" (?rfl_list_status@@3GA)
error LNK2001: unresolved external symbol "unsigned …
Run Code Online (Sandbox Code Playgroud)

c++ linker linker-errors

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

使用命名空间来创建全局函数,但是获得多个定义的符号错误

这些函数是我的大多数程序对象将使用的实用程序类型的东西.我希望将它们放在命名空间中并使它们具有全局性.此命名空间在标头中定义,然后添加到我的预编译标头中.但是到目前为止,我已经在2个不同的对象中使用了这个命名空间中的函数,并且编译器在这两个对象上抛出了多次定义的符号错误.

命名空间文件

#ifndef UTILS_H
#define UTILS_H

#include <random>
#include <cmath>


namespace Utils
{
    extern int GetRandomBetween(int low, int high)
    {
        if (low < 0 || low >= high)
            return 0;
        int seed = high - low;

        return (rand() % seed) + low;
    }
};

#endif
Run Code Online (Sandbox Code Playgroud)

和我的precomp标题

// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#pragma once

#include "targetver.h"

//#define WIN32_LEAN_AND_MEAN             // Exclude …
Run Code Online (Sandbox Code Playgroud)

c++ linker-errors precompiled-headers

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

使用模板类时链接器错误?

   I'm getting an "unresolved external symbol "public:__thiscall hijo<int>::hijo<int>(void)" referenced in function_main
Run Code Online (Sandbox Code Playgroud)

我开始了一个新项目,因为我在另一个更大的项目上遇到了同样的错误.当我尝试使用new关键字分配空间时发生错误.如果这个错误是愚蠢请原谅我因为我在过去几个月没有编程.

  /********************file hijo.h******************/
#pragma once
#ifndef hijo_h
#define hijo_h

template <class A>
class hijo
{
public:
    hijo(void);
    ~hijo(void);
};
#endif


  /********************file hijo.cpp***************/
    #include "hijo.h"
#include <iostream>
using namespace std;

template <class A>
hijo<A>::hijo(void)
{
}
template <class A>
hijo<A>::~hijo(void)
{
}
  /*********************at main() function ***************/

#include <iostream>
#include "hijo.h"

int main(){

    hijo<int> *h = new hijo<int>; <----  PROBLEM AT THIS LINE

    system("pause");
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ inheritance templates linker-errors

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

无法通过"DllMain已定义"错误获取

我正在尝试为.dll注入写一个.dll库.而且由于这个事实,它必须有一个名为DllMain的例程,因为这将被用作入口点.我认为我的问题可能源于这样一个事实,即我在一个静态库中进行链接,该库使用了afxmt.h中的线程和互斥锁.因为在某个地方,包含这个导致链接器从mfcs100ud.lib链接,mfcs100ud.lib显然包含自己的DllMain版本.

这是给我带来麻烦的文件:

dllmain.cpp

#include "stdafx.h"
#include <stdio.h>
#include "NamedPipeLogger.h"

static CNamedPipeLogger m_PipeLogger("Log.txt");

BOOL APIENTRY DllMain(HANDLE hModule, 
                      DWORD  ul_reason_for_call, 
                      LPVOID lpReserved)
{
}
Run Code Online (Sandbox Code Playgroud)

这是dllmain.cpp包含的stdafx.h文件.

stdafx.h中

#pragma once

#define _AFXDLL
#include <Afx.h>

#include "targetver.h"

#define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
Run Code Online (Sandbox Code Playgroud)

这是我的错误消息:

错误32错误LNK2005:_DllMain @ 12已在dllmain.obj中定义D:\ xxxxx\xxxxx\xxxxxx\mfcs100ud.lib(dllmodul.obj)

我只是搞砸了,因为我不能将我的Dll入口点的名称更改为DllMain以外的其他名称?

c++ dll compiler-errors compilation linker-errors

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

RC2247:无法打开Rc文件:资源管理器无法加载资源; 加载失败

我有一个win 32项目,我正在努力,资源文件工作正常,直到昨天.现在当我尝试打开资源文件进行编辑时,它会崩溃并给我以下错误:

 C://program files/Microsoft SDKs/Windows/v6.0A/include/prsht.h(0)
 error RC2247: Symbol name too long
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我可能出错的地方或在哪里调查.rc文件是一个非常简单的对话框,带有静态文本和进度条.

windows winapi linker-errors visual-studio-2008 visual-c++

6
推荐指数
2
解决办法
6250
查看次数

testflight库和Xcode 5中没有任何变化现在说"ld:找不到-lTestFlight的库"

我已经创建了几个月的应用程序,突然Xcode 5不想构建它.它只是抱怨以下错误.

Ld build/Debug-iphonesimulator/appname.app/appname normal i386
cd /Users/myname/proyectos/appname/dev/iOS/appname
setenv IPHONEOS_DEPLOYMENT_TARGET 5.1
setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.sdk -L/Users/myname/proyectos/appname/dev/iOS/appname/build/Debug-iphonesimulator -L\"/Users/myname/proyectos/appname/dev/iOS/appname/appname/External/FlurryAnalytics\" -L\"/Users/myname/proyectos/appname/dev/iOS/appname/appname/External/SmartADServer\" -L\"/Users/myname/proyectos/appname/dev/iOS/appname/appname/External/TestFlight\" -F/Users/myname/proyectos/appname/dev/iOS/appname/build/Debug-iphonesimulator -F/Users/myname/proyectos/appname/dev/iOS/appname/appname/External -filelist /Users/myname/proyectos/appname/dev/iOS/appname/build/appname.build/Debug-iphonesimulator/Appname.build/Objects-normal/i386/appname.LinkFileList -Xlinker -objc_abi_version -Xlinker 2 -fobjc-arc -fobjc-link-runtime -Xlinker -no_implicit_dylibs -mios-simulator-version-min=5.1 -weak_framework AdSupport -framework Security -framework MessageUI -framework Twitter -framework CoreLocation -weak_framework CoreMotion -framework AudioToolbox -framework AVFoundation -framework MediaPlayer -framework SystemConfiguration -framework MobileCoreServices -lz -framework CFNetwork -framework QuartzCore -framework UIKit -framework Foundation -framework CoreGraphics -lTestFlight -framework comScore -lFlurry -Xlinker -dependency_info -Xlinker /Users/myname/proyectos/appname/dev/iOS/appname/build/appname.build/Debug-iphonesimulator/Appname.build/Objects-normal/i386/appname_dependency_info.dat -o /Users/myname/proyectos/appname/dev/iOS/appname/build/Debug-iphonesimulator/appname.app/appname

ld: …
Run Code Online (Sandbox Code Playgroud)

xcode linker-errors ios

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

为什么QCOMPARE(QString("1"),"1")导致链接器错误?

我正在探索Qt的单元测试框架,我注意到一件奇怪的事情 - 考虑到QString已经实现了相等运算符const char *,我本来希望QCOMPARE(QString("1"), "1")它可以工作,但它会导致链接器错误:

tst_untitled14test.obj:-1: error: LNK2019: unresolved external symbol "bool __cdecl QTest::qCompare<class QString,char const [2]>(class QString const &,char const (&)[2],char const *,char const *,char const *,int)" (??$qCompare@VQString@@$$BY01$$CBD@QTest@@YA_NABVQString@@AAY01$$CBDPBD22H@Z) referenced in function "private: void __thiscall Untitled14Test::testCase1(void)" (?testCase1@Untitled14Test@@AAEXXZ)
Run Code Online (Sandbox Code Playgroud)

示例代码:

QVERIFY(QString("1") == "1");         // This works.
QCOMPARE(QString("1"), QString("1")); // This works.
// QCOMPARE(QString("1"), "1");       // Causes a linker error!
Run Code Online (Sandbox Code Playgroud)

这是为什么?不QCOMPARE使用2项的等式运算符?

编辑:由于在评论中询问,该项目是由Qt Creator的单元测试向导(文件 - >新项目 - >其他项目 - > Qt单元测试)创建的,所以当然它已经正确设置,并QT += testlib包含在内.

c++ qt unit-testing linker-errors

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

在Visual Studio中从asm调用C标准库函数

我在Visual Studio中创建的asm项目调用C函数时遇到问题(Win10 x64,Visual Studio 2015).项目由一个asm文件组成:

.586
.model flat, stdcall
option casemap:none
includelib msvcrt.lib

ExitProcess PROTO return:DWORD
extern printf:near

.data
text BYTE "Text", 0

.code
main PROC
    push offset text
    call printf
    add esp,4
    invoke ExitProcess,0
main ENDP
end main
Run Code Online (Sandbox Code Playgroud)

当我构建项目时,链接器输出错误:

错误LNK2019未解析的函数_main @ 0中引用的外部符号_printf

链接器输出参数:

/OUT:"C:\Users\apple\Documents\SP_Lab7\Debug\SP_Lab7_Demo.exe"/ MANIFEST:NO/NXCOMPAT /PDB:"C:\Users\apple\Documents\SP_Lab7\Debug\SP_Lab7_Demo.pdb"/ DYNAMICBASE "kernel32.lib""user32.lib""gdi32.lib""winspool.lib""comdlg32.lib""advapi32.lib""shell32.lib""ole32.lib""oleaut32.lib""uuid.lib" "odbc32.lib""odbccp32.lib"/ MACHINE:X86/SAFESEH:NO/INCREMENTAL:NO /PGD:"C:\Users\apple\Documents\SP_Lab7\Debug\SP_Lab7_Demo.pgd"/ SUBSYSTEM:WINDOWS/MANIFESTUAC: "level ='asInvoker'uiAccess ='false'"/ ManifestFile:"Debug\SP_Lab7_Demo.exe.intermediate.manifest"/ ERRORREPORT:PROMPT/NOLOGO/TLBID:1

如果我发表评论call print,那么一切都正常执行(甚至是Windows API函数).有没有办法从asm文件调用C函数而不创建包含的cpp文件<cstdio>?有可能吗?

x86 assembly masm linker-errors visual-studio

6
推荐指数
2
解决办法
4388
查看次数