使用代码块编译64位DLL会导致链接器错误 我在C++ 7上编写了一个非常简单的DLL程序,在Windows 64上。我制作了两个版本,64位和32位。我使用链接器编译的32位项目和设置了-m32标志的编译器。我使用-std=c++11。代码如下:

使用代码块编译64位DLL会导致链接器错误 我在C++ 7上编写了一个非常简单的DLL程序,在Windows 64上。我制作了两个版本,64位和32位。我使用链接器编译的32位项目和设置了-m32标志的编译器。我使用-std=c++11。代码如下:,c++,windows,dll,linker,64-bit,C++,Windows,Dll,Linker,64 Bit,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_EXPO

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__
DLL编译良好,在32位版本中运行良好。但是当我通过删除所有内容上的
-m32
选项编译到64位时,我得到一个链接器错误:

obj\Release\main.o:main.cpp | |未定义对“\u imp\u 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头文件?非常感谢您的指导!:)

修正了,我是个白痴。很久以前,我在“编译器和调试器”下的链接器设置中将
-m32
设置为永久性标志。将其删除后,现在可以完美地工作。

我知道,这只是为了测试,但不要从
DllMain
调用
MessageBox
(请参阅)。不过打电话是安全的。另一方面,由于您使用的是Code::Blocks,而且默认设置的选择很差:您绝对应该积极调用Windows API的Unicode版本(即MessageBoxW,而不是MessageBoxA)。非常好,谢谢!
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)