c++ - 使用CodeBlocks编译64位DLL会导致链接器错误

标签 c++ windows dll linker 64-bit

我已经在Windows 7 64位上用C++准备了一个非常简单的DLL程序。我制作了两个版本,即64位和32位。我使用链接器和带有-m32标志设置的编译器进行编译的32位项目。我使用-std=c++11。这是它的代码:

主文件

#ifndef __MAIN_H__
#define __MAIN_H__

#include <windows.h>

/*  To use this exported function of dll, include this header
 *  in your project.
 */

#ifdef BUILD_DLL
    #define DLL_EXPORT __declspec(dllexport)
#else
    #define DLL_EXPORT __declspec(dllimport)
#endif


#ifdef __cplusplus
extern "C"
{
#endif

void DLL_EXPORT SomeFunction(const LPCSTR sometext);

#ifdef __cplusplus
}
#endif

#endif // __MAIN_H__

main.cpp
#include "main.h"

// a sample exported function
void DLL_EXPORT SomeFunction(const LPCSTR sometext)
{
    MessageBoxA(0, sometext, "DLL Message", MB_OK | MB_ICONINFORMATION);
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    switch (fdwReason)
    {
        case DLL_PROCESS_ATTACH:
            MessageBoxA(0, "DLL_PROCESS_ATTACH", "DLL Message", MB_OK | MB_ICONINFORMATION);
            break;

        case DLL_PROCESS_DETACH:
            MessageBoxA(0, "DLL_PROCESS_DETACH", "DLL Message", MB_OK | MB_ICONINFORMATION);
            break;

        case DLL_THREAD_ATTACH:
            MessageBoxA(0, "DLL_THREAD_ATTACH", "DLL Message", MB_OK | MB_ICONINFORMATION);
            break;

        case DLL_THREAD_DETACH:
            MessageBoxA(0, "DLL_THREAD_DETACH", "DLL Message", MB_OK | MB_ICONINFORMATION);
            break;
    }
    return TRUE; // succesful
}

DLL可以很好地编译,并且可以在32位版本中很好地工作。但是,当我通过删除所有内容的-m32选项编译为64位时,出现链接器错误:

obj \ Release \ main.o:main.cpp ||未定义对`_imp_MessageBoxA'|的引用

-m64替换无济于事。这是我的MingW版本详细信息:
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-g++.exe
COLLECT_LTO_WRAPPER=E:/Program\ Files\ (x86)/CodeBlocks/MinGW/bin/../libexec/gcc/x86_64-w64-mingw32/5.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-5.1.0/configure --build=x86_64-w64-mingw32 --enable-targets=all --enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto --enable-graphite --enable-cxx-flags=-DWINPTHREAD_STATIC --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-libstdcxx-debug --enable-threads=posix --enable-version-specific-runtime-libs --enable-fully-dynamic-string --enable-libstdcxx-threads --enable-libstdcxx-time --with-gnu-ld --disable-werror --disable-nls --disable-win32-registry --prefix=/mingw64tdm --with-local-prefix=/mingw64tdm --with-pkgversion=tdm64-1 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: posix
gcc version 5.1.0 (tdm64-1) 

我可能做错了什么?是否可能需要包含一个特殊的64位Windows header ?非常感谢您的指导! :)

最佳答案

固定,我是个白痴。很久以前,我已经在“编译器和调试器”下的链接器设置中将-m32设置为永久标记。删除它,现在可以正常使用了。

关于c++ - 使用CodeBlocks编译64位DLL会导致链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37447097/

相关文章:

c++ - 在 CUDA 中,如何将设备内存分配给我的指针数组?

c++ - 无法将结构数组传递给函数

c++ - 以编程方式在默认浏览器中打开多个 URL

.net - 在不停止服务的情况下更新 dll

.net - 在哪里可以获得 Microft SharePoint 程序集?

c++ - 如何检测和处理算法中不受支持的语言环境?

c# - 如何调试挂起的 WPF 应用程序?

node.js - 如何在 Windows 上使用 nodemon 设置 NODE_ENV=production?

windows - 无法使用 powershell 从 32 位版本的 win2008 读取 64 位注册表项

C#访问简单的C dll