c++ - 在Linux上为Windows构建GCC插件

标签 c++ c gcc plugins compiler-construction

尝试使用mingw cross编译器在Linux上为Windows构建以下gcc插件。插件来自Windows的内置avr编译器。修改了以下插件https://github.com/jcmvbkbc/avr-flash-vtbl

#include <gcc-plugin.h>
#include <cp/cp-tree.h>

#ifdef _WIN32
__declspec(dllexport)
#endif

int plugin_is_GPL_compatible = 1;

void fn(void *gcc_data, void *user_data)
{
    TYPE_ADDR_SPACE (TREE_TYPE (vtbl_type_node)) = 1;
    TYPE_ADDR_SPACE (TREE_TYPE (vtbl_ptr_type_node)) = 1;
}

#ifdef _WIN32
__declspec(dllexport)
#endif    

int plugin_init (struct plugin_name_args *plugin_info,
         struct plugin_gcc_version *version)
{
    register_callback("", PLUGIN_START_UNIT, fn, NULL);
    return 0;
}

编译和链接期间的输出:
i686-w64-mingw32-g++ -shared -I/home/andreas/omgwtfbbq/win64/bin/../lib/gcc/avr/9.2.0/plugin/include -Wl,--export-all-symbols /home/andreas/
omgwtfbbq/win64/bin/../lib/gcc/avr/9.2.0/plugin/cc1plus.exe.a avr-flash-vtbl.c -o avr-flash-vtbl.so -I./
/usr/bin/i686-w64-mingw32-ld: /tmp/cc28ZVde.o:avr-flash-vtbl.c:(.text+0x4): undefined reference to `cp_global_trees'
/usr/bin/i686-w64-mingw32-ld: /tmp/cc28ZVde.o:avr-flash-vtbl.c:(.text+0x10): undefined reference to `cp_global_trees'
/usr/bin/i686-w64-mingw32-ld: /tmp/cc28ZVde.o:avr-flash-vtbl.c:(.text+0x44): undefined reference to `register_callback'
collect2: error: ld returned 1 exit status
make: *** [Makefile:11: avr-flash-vtbl.so] Fehler 1

编译器标志来自https://gcc.gnu.org/onlinedocs/gccint/Plugins-building.html。有人已经遇到过这样的问题吗?

最佳答案

问题解决了。将主机编译器从i686-w64-mingw32-g++更改为x86_64-w64-mingw32-g++,并更改了选项的顺序。 /home/andreas/omgwtfbbq/win64/bin/../lib/gcc/avr/9.2.0/plugin/cc1plus.exe.a必须放在avr-flash-vtbl.c之后。

关于c++ - 在Linux上为Windows构建GCC插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60467609/

相关文章:

C++ typedef 修复模板参数

c++ - 取消引用时不一致返回空 shared_ptr

c++ - 如何使用递归来反转用户输入?

c - 使用一根管道在父子之间进行读写

c - 从 gcc 引出 "unrecognized command line option"

c++ - “rusage” 统计

c++ - 使用 automake 构建 gSoap 应用程序时的不同行为

arrays - 如何通过数组指针访问数组的各个元素?

c - 为什么gcc生成 "leal -8240(%ebp), %eax; cmpl $1, %eax; ja XXX"而不是jmp指令?

c++ - 如何在 Linux gcc 下确定 vswprintf 的缓冲区大小