brechtsanders / winlibs_mingw

winlibs standalone build of GCC compiler and MinGW-w64
917 stars 40 forks source link

Can't find cc1.exe.a for plugin #230

Open coco875 opened 1 month ago

coco875 commented 1 month ago

gcc give the abilities to make some plugin but from https://gcc.gnu.org/onlinedocs/gccint/Plugins-building.html it's say for windows it require add cc1.exe.a who are in plugin directory at the same level that all include but can't find it and without it I get:

$ g++ -shared -IC:/Users/perei/Documents/GitHub/C-hook-static/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/plugin/include -fPIC -fno-rtti -O2 -Wl,--export-all-symbols plugin1.c -o plugin.so
C:/Users/username/Documents/GitHub/C-hook-static/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\tmp\ccoCJLgn.o:plugin1.c:(.text+0x57): undefined reference to `register_callback'
C:/Users/username/Documents/GitHub/C-hook-static/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/14.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\tmp\ccoCJLgn.o:plugin1.c:(.text+0x8): undefined reference to `register_attribute(attribute_spec const*)'
coco875 commented 1 month ago

just in case the code I try to compile:

#include "gcc-plugin.h"
#include "plugin-version.h"
#include "tree.h"

#ifdef _WIN32
__declspec(dllexport)
#endif
int plugin_is_GPL_compatible;

/* Attribute handler callback */
static tree handle_hook_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs) {
    printf("hello hook!\n");
    return NULL_TREE;
}

/* Attribute definition */
static struct attribute_spec hook_attr =
    { "hook", 1, 1, false,  false, false, false, handle_hook_attribute, NULL };

/* Plugin callback called during attribute registration.
Registered with register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL)
*/
static void register_attributes(void *event_data, void *data) {
    register_attribute(&hook_attr);
}

#ifdef _WIN32
__declspec(dllexport)
#endif
int plugin_init (struct plugin_name_args *plugin_info, struct plugin_gcc_version *version) {
    const char *plugin_name = plugin_info->base_name;
    printf("Hello, World!\n");
    register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
    return 0;
}
coco875 commented 1 month ago

I succeed to found it in https://packages.msys2.org/package/mingw-w64-x86_64-gcc but not in mingw distribute or w64devkit and in winlibs there is header but not cc1plus.exe.a or cc1.exe.a

brechtsanders commented 1 month ago

I do build GCC with the --enable-plugin flag, but no .exe.a files are generated.

But I don't know why that's the case.