Home > Software engineering >  usr/bin/ld skipping incompatible ./libSPECcon.so when searching for -lSPECcon
usr/bin/ld skipping incompatible ./libSPECcon.so when searching for -lSPECcon

Time:07-30

Currently, I'm using Ubuntu 22.04. I have main.cpp and a .so file. I got this error when i try to compile with following command g -L. -Wall -o code main.cpp -lSPECcon.

.so file and main.cpp are in the same folder

It gives me this output:

main.cpp: In function ‘int main(int, char**):
main.cpp:51:22: warning: ISO C   forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   51 |         char *port = "ttyUSB0";
      |                      ^~~~~~~~~
main.cpp:58:26: warning: ISO C   forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   58 |         char *filename = "/home/karun/spec/SPECcon/SPECcon_1.3/Examples/c  /example_cs.txt";
      |                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:98:21: warning: ISO C   forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   98 |         char *arg = "3";
      |                     ^~~
main.cpp:99:21: warning: ISO C   forbids converting a string constant to ‘char*’ [-Wwrite-strings]
   99 |         char *cmd = "M"; // Executing the command *para:gain from example.txt
      |                     ^~~
main.cpp:42:34: warning: unused variable ‘DLL_supported_baudrates’ [-Wunused-variable]
   42 |         SPEC_supported_baudrates DLL_supported_baudrates = (SPEC_supported_baudrates)dlsym(hGetProcIDDLL, "SPEC_supported_baudrates");
      |                                  ^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:54:13: warning: variable ‘ret’ set but not used [-Wunused-but-set-variable]
   54 |         int ret = DLL_identify_spectrometer(port, baud, firmware);
      |             ^~~
/usr/bin/ld: skipping incompatible ./libSPECcon.so when searching for -lSPECcon
/usr/bin/ld: cannot find -lSPECcon: No such file or directory
/usr/bin/ld: skipping incompatible ./libSPECcon.so when searching for -lSPECcon
collect2: error: ld returned 1 exit status

How do i solve this problem?

CodePudding user response:

I solve the problem by linking my .so file to /usr/lib. This question helped me: usr/bin/ld: cannot find -l<nameOfTheLibrary>

  • Related