将使用不同gcc生成的dll链接在一起,错误:文件无法识别:文件格式无法识别



我正试图用GCC 4.6.1在C++0x中构建一个项目,该项目与用GCC 11.2.0生成的C++17 dll链接。我使用的是Netbeans IDE 7.4(我认为这无关紧要(。

因此,编译(使用GCC 4.6.1(的输出如下:CCD_ 1。libdriver17.dll确实是我用GCC 11.2.0生成的dll。

我的驱动程序driver17.h:

#ifndef DRIVER_H
#define DRIVER_H
#include <stdarg.h>
#ifdef __cplusplus
extern "C" {
#endif
const char* __stdcall init_driver(void);
#ifdef __cplusplus
}
#endif
#endif /* DRIVER_H */

driver17.cpp:

#include <string>
#include "driver17.h"
std::string my_str;
const char* init_driver(){
int x = 45;
my_str = std::to_string(x);
return my_str.c_str();
}

main_cpp0x.cpp:

#include "../dependencies/driver17.h"
#include <iostream>
int main(){
std::cout<<init_driver()<<std::endl;
}

我的c++0xMakefile:

g++ -std=c++0x main_cpp0x.cpp -o test -I../dependencies -L../dependencies -ldriver17

dependencies确实是我的依赖项所在。。。(driver17.hlibdriver17.dll(。

我认为可以将不同的gcc构建的dll链接在一起,但我不知道我做错了什么。

我正在使用Windows btw.

谢谢。

我用64位编译libdriver17.dll: file not recognized: File format not recognized0,用32位编译main_cpp0x.cpp

最新更新