简体   繁体   English

调用静态库中定义的全局函数导致链接器错误

[英]Calling Global function defined in static library causes linker error

I have created a simple static library project and a Win32 console project to call a function.我创建了一个简单的静态库项目和一个 Win32 控制台项目来调用函数。

// static lib code
// Test.h
void abf();

// Test.cpp
void abf()
{
}

// Caller Project code
// MyTest.cpp
#include "Test.h
int main()
{
    abf();
    return 0;
}

Static library compiles without an error.静态库编译没有错误。 But caller project gives following error.但是调用者项目给出了以下错误。

error LNK2019: unresolved external symbol "void __cdecl abf(void)" (?abf@@YAXXZ) referenced in function _main

I tried a few things such as putting the function in extern "C" block, exporting using __declspec(dllexport) but nothing seems to work.我尝试了一些方法,例如将函数放在 extern "C" 块中,使用 __declspec(dllexport) 导出,但似乎没有任何效果。

Any ideas?有任何想法吗?

在 test.h 中使用 __declspec(dllexport) 导出您的符号

extern "C" __declspec(dllexport) void abf(void);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM