0

I have written a few programs and while trying to compile them using g++,as thus,

$ g++ minIni.c device_datum.cpp fanuc_axis.cpp fanuc_path.cpp service.cpp condition.cpp cutting_tool.cpp string_buffer.cpp logger.cpp client.cpp server.cpp adapter.cpp fanuc_adapter.cpp FanucAdapter.cpp -L/usr/local/lib/ -lfwlib32 -lpthread -o adapter 

I keep getting the following error:

/usr/bin/ld: cannot find -lfwlib32 collect2: error: ld returned 1 exit status 

fwlib32.h is the library I am trying to include. The shared object file libfwlib32.so is present in /usr/local/lib as well as /usr/lib. But I am unable link to it. I have tried all the solutions offered by similar questions including

$ export LIBRARY_PATH=/usr/local/lib/

$ export LD_LIBRARY_PATH=/usr/local/lib

I have done the above for /usr/lib as well, but still the same error. I have tried using the -L option in the command line but I still get the error.

I even created a new folder called lib, pasted libfwlib32.so.1.0.1 into it and ran

$ ln -s ~/lib/libfwlib32.so.1.0.1 ~/lib/libfwlib32.so

on the console to create a new .so file and gave ~/lib as argument to -L option on the command line. It made no difference. I am at the point of tearing my hair out so any help will be appreciated.

Thanks alot!

3 Answers 3

1

You should put -l option in the very last as:

$ g++ minIni.c device_datum.cpp fanuc_axis.cpp fanuc_path.cpp service.cpp condition.cpp cutting_tool.cpp string_buffer.cpp logger.cpp client.cpp server.cpp adapter.cpp fanuc_adapter.cpp FanucAdapter.cpp -L/usr/local/lib/ -o adapter -lfwlib32 -lpthread 

Note: Please make sure that all the header and source file are in the same folder.

Sign up to request clarification or add additional context in comments.

1 Comment

Whoa that worked! I mean placing -l option at the end of the command. Thanks @Abhijatya.
0

Note that specifying -L~/lib won't work as the ~ will not be expanded by the shell. Also you can't add a space between -L and ~/lib. Instead you must specify it as a relative or absolute path.

Have you checked that the libfwlib32.so symlink exists in /usr/local/lib (or /usr/lib) in addition to the libfwlib32.so.1.0.1 file?

Another possibility is that the library is the wrong architecture (ie. 32-bit while your system is 64-bit), but then ld should print a message about skipping incompatible library. You can check the architecture of the library by running 'file libfwlib32.so.1.0.1'.

3 Comments

Yes libfwlib32.so does exist in /usr/local/lib as well as /usr/lib. I ran 'sudo file libfwlib32.so.1.0.1' and it showed the file to be 32 bit version, while my system is 64-bit. However, I have used the library file for programming via netbeans and it ran successfully. I am compiling via the terminal right now. The extra item to add to the command line would be '-m32' right? That results in the same error message being displayed. And as you said, I don't see any messages about 'skipping incompatible file'.
The only other thing I can think of is that the permissions on libfwlib32.so.1.0.1 is wrong. Can you run 'ls -l' on both the library and symlink to check that the files are readable for you user?
I just ran the files in a netbeans project and they executed successfully. I'm confused. I thought maybe there was some problem with g++ on my system, but since g++ works fine on netbeans, it should work in the terminal as well right? The ls -l command shows I have read-write permission for libfwlib32.so.1.0.1. For the file libfwlib32.so I have read-write-execute permission.
0

The error message suggests that -lfwlib32 is being interpreted as a filename not as a -l parameter. Put all the parameters before the files to be compiled

g++ -m32 -L/usr/local/lib/ -lfwlib32 -lpthread -o adapter minIni.c device_datum.cpp fanuc_axis.cpp fanuc_path.cpp service.cpp condition.cpp cutting_tool.cpp string_buffer.cpp logger.cpp client.cpp server.cpp adapter.cpp fanuc_adapter.cpp FanucAdapter.cpp 

As has been pointed out by @Erik Johannessen, libfwlib32.so is a 32bit library, so you need to add -m32 to build a 32bit executable.

3 Comments

Tried it mate. Same result.
You will need -m32 as well to build a 32bit executable.
Yup. Did that. But I still get the error. The funny thing is, I just ran the same files in a netbeans project and I got the output. But I'm wondering what is wrong when I try to run on the terminal.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.