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

时间:2016-05-25 20:32:37

标签: c++ windows dll linker 64-bit

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

main.h

#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 \发布\ 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标头?非常感谢任何方向! :)

1 个答案:

答案 0 :(得分:0)

修正了,我是个白痴。很久以前,我在{34;编译器和调试器'下的链接器设置中将-m32设置为永久标志。&#34;删除它,现在完美地工作。