![](/img/trans.png)
[英]Linker fails to find 32-bit libraries under 64-bit Mint OS when compiling with Clang
[英]Compiling a 64-bit DLL with CodeBlocks gives linker errors
我在 Windows 7 64 位上用 C++ 准備了一個非常簡單的 DLL 程序。 我制作了兩個版本,64 位和 32 位。 我使用鏈接器編譯的 32 位項目,編譯器設置為-m32
標志。 我使用-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__
主文件
#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 標頭? 非常感謝任何方向! :)
修正,我是個白痴。 很久以前,我在“編譯器和調試器”下的鏈接器設置中將-m32
設置為永久標志。 刪除它,現在完美運行。
這很簡單,你只需設置 Global Compiler Settings,然后設置 Compiler Flag,選擇 General C++ 14 GNU C++,祝你好運
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.