Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm c++ programmer, but fairly new to developing on linux platforms.
I am trying to build an application that uses a share library providing API implementation.
To test library linking, I have written a simplest main.cpp that calls most basic function from this shared library.
I get following error while linking main.o >>>>>>>>
$ g++ main.o -o main.exe -L /usr/lib -l :libmylib.so
/usr/lib/gcc/pc/i686-pc-cygwin/../../../libmylib.so: Could not read symbols: File in wrong format
>>>>>>>
/usr/lib/libmylib.so is symbolic link to the actual shared library.
The 'file' command gives below output >>>>>>>
$ file -L <actual lib name>
<Actual libname>: ELF 32-bit LSB shared object, Intel 80386, Version 1(SYSV), dynamically linked, stripped
>>>>>>>>
Also, I can see all the functions using "nm -D" or "readelf" tools.
What might be wrong here? I am using Cygwin environment to emulate linux.
I just have one library which is .so
I don't have source code for that.
When I try static linking (-Wl,-Bstatic), the error says "Attempted static link of dynamic object <libname>"
When I try dynamic linking (-Wl,-Bdynamic), the error says "Could not read symbols: File in wrong format".
Is this because I am using cygwin?
I don't think it should be a problem.
Yes I have the library placed in /usr/lib (I think that's what you mean by install, right?)
I'm not even trying to run the app, the problem is in the build stage.
Also, I don't need static linking, I'm good with dynamic linking.
I checked the architecture of my object (main.o) and library file - both are 32-bit.
These are some one the commands I tried, but all fail with same error
$ gcc maino -o main -L/usr/lib -lmylib
$ gcc maino -o main -L/usr/lib -l:libmylib.so
$ gcc maino -o main -L/usr/lib -Wl,-Bdynamic -l:libmylib.so
The error always says "could not read symbols: file in wrong format"
Thanks so much for your effort to see me thru this!
I checked the page you mentioned and lot of other stuff on net.
Generally, it is beleived that this can happen only if library is originally compiled with different architecture.
So I'm going with the theory that something is wrong with the library itself and not the way I'm trying to link it.
Just to be sure, I'm going to install linux VM (instead of cygwin) and see if i can get it to work on it.
So I found the problem and it was 'cygwin' I guess.
I was under the impression that cygwin emulates linux shell and build environment on windows.
But seems compilers in cygwin build windows executable and expect windows DLLs as 'shared libraries'.
I installed coLinux with debian FS, it took me a while to figure out and fix various issues.
But it working great and I'm able to build linux binaries using coLinux.
Now I need to hunt for nice GUI based IDE for linux based c++ projects.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.