【问题标题】:Linking together dlls built with different gcc, error : file not recognized: File format not recognized将使用不同 gcc 构建的 dll 链接在一起,错误:文件无法识别:文件格式无法识别
【发布时间】:2022-01-14 02:57:47
【问题描述】:

我正在尝试使用 GCC 4.6.1 在 C++0x 中构建一个项目,该项目与使用 GCC 11.2.0 生成的 C++17 dll 链接。 我正在使用 Netbeans IDE 7.4(我认为没关系)。

因此,编译(使用 GCC 4.6.1)输出如下: libdriver17.dll: file not recognized: File format not recognizedlibdriver17.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++0x Makefile:

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

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

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

顺便说一句,我正在使用 Windows。

谢谢。

【问题讨论】:

    标签: c++ gcc compiler-errors compilation


    【解决方案1】:

    我正在编译 64 位的 driver17 和 32 位的 main_cpp0x.cpp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-25
      • 2021-01-13
      • 1970-01-01
      • 2017-10-14
      • 2018-02-15
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      相关资源
      最近更新 更多