audiohacked / OpenCorsairLink

Linux and Mac OS support for the CorsairLink Devices
GNU General Public License v2.0
705 stars 125 forks source link

(gcc 10.1.0) ld: multiple definition of 'scanlist' error #241

Closed Abh15h3k closed 4 years ago

Abh15h3k commented 4 years ago

OS: Artix Linux ( using openrc )

Im trying install opencorsairlink-git from the AUR using yay. but i get the following error.

cc main.o device.o logic/options.o logic/options_fan.o logic/options_led.o logic/options_pump.o logic/print.o logic/scan.o logic/settings/commanderpro.o logic/settings/hydro_asetek.o logic/settings/hydro_asetekpro.o logic/settings/hydro_coolit.o logic/settings/psu.o drivers/asetek.o drivers/asetekpro.o drivers/commanderpro.o drivers/coolit_old.o drivers/coolit.o drivers/dongle.o drivers/rmi.o drivers/unsupported.o protocol/asetek/core.o protocol/asetek/fan.o protocol/asetek/led.o protocol/asetek/pump.o protocol/asetek/temperature.o protocol/asetekpro/core.o protocol/asetekpro/fan.o protocol/asetekpro/led.o protocol/asetekpro/pump.o protocol/asetekpro/temperature.o protocol/commanderpro/core.o protocol/commanderpro/fan.o protocol/commanderpro/power.o protocol/commanderpro/temperature.o protocol/rmi/core.o protocol/rmi/power.o protocol/rmi/temperature.o protocol/rmi/time.o protocol/coolit/core.o protocol/coolit/fan.o protocol/coolit/led.o protocol/coolit/pump.o protocol/coolit/temperature.o lowlevel/asetek.o lowlevel/commanderpro.o lowlevel/coolit.o lowlevel/rmi.o -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -std=c99 -Iinclude -I/usr/include/libusb-1.0 -DVERSION=\"v0.9.0.0-e2bd\" -Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now -lm -lusb-1.0 -o OpenCorsairLink.elf /usr/sbin/ld: logic/scan.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: multiple definition of scanlist'; main.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: first defined here /usr/sbin/ld: logic/settings/commanderpro.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: multiple definition ofscanlist'; main.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: first defined here /usr/sbin/ld: logic/settings/hydro_asetek.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: multiple definition of scanlist'; main.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: first defined here /usr/sbin/ld: logic/settings/hydro_asetekpro.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: multiple definition ofscanlist'; main.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: first defined here /usr/sbin/ld: logic/settings/hydro_coolit.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: multiple definition of scanlist'; main.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: first defined here /usr/sbin/ld: logic/settings/psu.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: multiple definition ofscanlist'; main.o:/tmp/yaourt-tmp-abhishek/aur-opencorsairlink-git/src/OpenCorsairLink/include/logic/scan.h:30: first defined here collect2: error: ld returned 1 exit status make: *** [Makefile:150: OpenCorsairLink.elf] Error 1

Abh15h3k commented 4 years ago

So after a while i realised that my gcc version is 10.1.0 and that is the reason opencorsaillink does not build successfully. I have confirmed this by downgrading to gcc 9.3.0 ( by downloading it from archive.archlinux.org ). After which the package build properly

Abh15h3k commented 4 years ago

Ok. So i have a workaround for people who might not want to downgrade their gcc to 9.3.0.

The linker errors out because scanlist ( from include/logic/scan.h ) is getting redefined in main.c and logic/scan.c

so i removed the "scanlist[10]" from logic/scan.h and declared them individually in main.c and scan.c (with different variable name, otherwise the linker will still report one redefinition error).

so in include/logic/scan.h:

change this

struct corsair_device_scan
{
    struct corsair_device_info* device;

   /** libusb device structures **/
    struct libusb_device_handle* handle;
} scanlist[10] ;

To this

struct corsair_device_scan
{
    struct corsair_device_info* device;

   /** libusb device structures **/
    struct libusb_device_handle* handle;
};

and in main.c right after all the includes i added: struct corsair_scan_device slist[10]; and change all occurrences of scanlist as well ( all of them are between line 100 and 120 )

and in logic/scan.c: ( right after the includes again ) struct corsair_scan_device scanlist[10];

I'm sure this is not best/correct way to do it. but this is what i could figure what in the small time i spent tinkering with this. Hopefully this info helps fixing (the right way) the linker errors

duxet commented 4 years ago

It's easier to just add CFLAGS += -fcommon line to Makefile

Abh15h3k commented 4 years ago

It's easier to just add CFLAGS += -fcommon line to Makefile

Oh cool. But does that exactly do?

audiohacked commented 4 years ago

Thanks for submitting a bug report. The fix should be in the testing branch.

P.S. I will warn you that I do not support AUR/PKGBUILDs.