fungos / cr

cr.h: A Simple C Hot Reload Header-only Library
https://fungos.github.io/cr-simple-c-hot-reload/
MIT License
1.54k stars 101 forks source link

Can't load plugins on linux #56

Closed Kiakra closed 4 years ago

Kiakra commented 4 years ago

Hello, i was using this library on macos and it worked just fine with my setup and project. I switch to the linux and i compiled it but the cr_plugin_update() function returns -2. According to the cr.h file // -2 to differentiate from crash handling code path, meaning the crash // happened probably during load or unload and not update I didn't understand why this happened, so i tried to run the samples with fips. It worked but i use shell scripts for compiling for my projects and i tried to compile the basic_guest and basic_host files like this clang -shared basic_guest.c -fPIC -o basic_guest.so clang++ -std=c++17 basic_host.cpp -ldl -o basic_host

and again, the cr_plugin_update() function gives me -2 I am 100% sure i am putting the exact path to the plugin. From what i understand it is a compiler thing. I also tried using optimizations(and without it), with gcc, looked at auto generated fips files and used the flags that fips used still not working

fungos commented 4 years ago

Hello, you're missing two things, the first is the lib prefix for linux (you can change it in the CR_PLUGIN macro if you want, but try this: clang -shared basic_guest.c -fPIC -o libbasic_guest.so

and then, the CR_DEPLOY_PATH in the second command (which you can also change to something specific to your setup): clang++ -std=c++17 basic_host.cpp -DCR_DEPLOY_PATH="\".\"" -ldl -o basic_host

With these, you should be able to find the plugin.

If you want to contribute a Makefile for the samples, please submit a PR and I'll gladly accept it.

Kiakra commented 4 years ago

Oh, i did not see lib prefix. Thank you for your reply this solved my problem. If i find a empty space for makefiles, i will probably open a PR for it.