【问题标题】:Building gcc plugin for windows on linux在 linux 上为 windows 构建 gcc 插件
【发布时间】:2020-06-13 11:53:34
【问题描述】:

尝试使用mingw交叉编译器在linux上为windows构建以下gcc插件。这些插件来自内置的 avr 编译器,也适用于 Windows。改编了以下插件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。有人遇到过这样的问题吗?

【问题讨论】:

  • 启用插件的 Avr 编译器,为其构建插件:Win64: ig5tf1xybtmow6m2.myfritz.net:49293/nas/…
  • 问题已解决。将主机编译器从 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++ c gcc plugins compiler-construction


【解决方案1】:

问题解决了。将主机编译器从 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 之后。

【讨论】:

    猜你喜欢
    • 2010-10-06
    • 1970-01-01
    • 2012-12-19
    • 2016-08-18
    • 2022-12-18
    • 2022-06-28
    • 2013-07-10
    • 2020-08-25
    • 1970-01-01
    相关资源
    最近更新 更多