why is -ldgcc option not working in my make file - c

im trying to complie some operating system example code and when i run make (in running the default debian eviroment on a chromebook lunix termial) it gives me the folowing error:
kuzai_longmane#penguin:/mnt/chromeos/removable/32GB/Operating systems (source code)/my_cool_os/my_cool_os$ make
gcc -m32 -nostdlib -nodefaultlibs -lgcc start.o libc/string/memcmp.o libc/string/memset.o libc/string/strcat.o libc/string/strchr.o libc/string/strcmp.o libc/string/strcpy.o libc/string/strlen.o libc/string/strncmp.o libc/string/strstr.o libc/string/strutil.o libc/string/ctos.o kernel/tty.o kernel/io.o kernel.o -T linker.ld -o myos
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/10/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: error: ld returned 1 exit status
make: *** [Makefile:28: myos] Error 1
any sugestions or things i overlooked?

You're trying to generate and link 32-bit code (the -m32 option), but the linker can't find a 32-bit version of libgcc. The message says its is finding a 64-bit version, so the problem is probably just that you don't have 32-bit libs installed. I think on debian, you need to install the ia32-libs package for that.

Related

Unable to compile C++ programs on CentOS

I am getting the below error during ./configure.
configure:3429: checking whether the C compiler works
configure:3451: gcc -m32 -D_FILE_OFFSET_BITS=64 -m32 conftest.c >&5
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-redhat-linux/4.4.7/libgcc_s.so when searching for -lgcc_s
/usr/bin/ld: cannot find -lgcc_s
collect2: ld returned 1 exit status
configure:3455: $? = 1
configure:3493: result: no
configure:3498: error: in `/root/cjk/1.x/src/externals/mecab':
configure:3500: error: C compiler cannot create executables
I have tried couple of solutions mentioned in internet but to no avail.
I have installed complete Developers package in the machine.
I have installed glibc-devel.i686 package as well.
I ran into the exact same issue (CentOS 6.5 x64, gcc 4.4.7). I made sure yum install glibc-devel.i686 was performed. A quick find / -name "libgcc_s.*" revealed:
/lib64/libgcc_s.so.1
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/32/libgcc_s.so
/usr/lib/gcc/x86_64-redhat-linux/4.4.4/libgcc_s.so
So, perhaps you can try the workaround suggested here:
Add the absolute path to the gcc_s library on the link line, OR
(Recommended) If the library's filename has any major and minor version numbers appended to it, simply create a soft link to the library in the same location without the major and minor version numbers in the target filename.
I settled for compiling/linking my application statically by adding -static to my gcc invocation. So,
gcc -static -m32 ...
In that case make sure yum install glibc-static.i686 is done.

DSO missing from command line although it is available

I am working with c++ code for a physics simulation, which uses a lot of external libraries (like GSL and cern`s ROOT). Trying to recompile project I encountered problems with linking. When running compilation of final file via:
g++ -fno-inline -O2 -fpic -o main.out ${ROOTINCS} main.o ext.o ${ROOTLIBS} $(objects2)
with :
objects2= many .o files made by us
ROOTLIBS=-L/usr/local/lib/root -lTree -lRIO -lNet -lHist -lMathCore -lCore -lGraf -lGraf3d -lGpad -lMatrix -lThread -lCint -lPhysics -lPostscript -lRint -lSpectrum -lg
ROOTINCS=-pthread -m64
I get annoying error:
/usr/bin/ld: /usr/local/lib/root/libHist.so: undefined reference to symbol 'gRandom'
/usr/local/lib/root/libMathCore.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
The problem is nm -C run on libMathCore states 'gRandom' is declared there. Also -lMathCore is present in my command line.
When I run ld to check if it understands the flag:
ld -L/usr/local/lib/root -lMathCore --verbose 2>/dev/null
it does not complain and tries to link properly.
According to https://stackoverflow.com/a/24675715/3602168 order of libraries is correct in my linking (libHist uses libMathCOre and therefore is stated first).
Compilation runs under g++ 4.8.2 on ubuntu 14.04, 64 bit
Converting comment to answer:
Have you tried moving $(objects2) before ${ROOTLIBS}? I think the issue may be that you have libraries specified before the object files that use them.

Cannot find -lgcc -s while Compiling C program with GCC

I am trying to compile a C program with gcc using the below command
gcc -r client.c -o exe
But getting these errors, and no generation of exe file:
/usr/bin/ld cannot find -lgcc -s
collect2: ld returned 1 exit status
Anyone tell me what I am missing and what is ld here?
ld is the linker or link editor. It is invoked by gcc to link the .o files produced by compiling your code together with various libraries (including libgcc) to produce an executable (exe).
Why are you passing -r to gcc? Do you know what it does? Don't do that.

Compiling and Linking a C-Program for a 32-bit Architecture

So I'm working through an assignment for Stanford's CS107 course and I can't get past compiling the unfinished program (project files and the original makefile can be found on the course page, I'm working on assignment 4 RSS.)
After much research, I think the problem is I'm using gcc on a 64-bit architecture (Mac OS 10.6) and the pre-compiled library code under assn-4-rss-news-search-lib/linux is for a 32-bit architecture. I tried setting gcc to use i386 and -m36, but nothings working and I'm kind of just guessing.
So here's the output I get when I run make:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lnsl -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: library not found for -lnsl
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
Here's the output I get when I remove -lnsl where architecture differences are mentioned:
gcc -g -Wall -std=gnu99 -Wno-unused-function -c -o rss-news-search.o rss-news-search.c
gcc rss-news-search.o -g -Wall -std=gnu99 -Wno-unused-function -g -lrssnews -L/Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux -o rss-news-search
ld: warning: in /Users/derp/Documents/OCW/CS107/Work/programming4/assn-4-rss-news-search-lib/linux/librssnews.a, file was built for unsupported file format which is not the architecture being linked (x86_64)
Undefined symbols:
"_URLConnectionDispose", referenced from:
_ProcessFeed in rss-news-search.o
_ParseArticle in rss-news-search.o
... several more undefined symbols mentioned ...
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [rss-news-search] Error 1
So I'm asking for any ideas on what I could do to resolve this. I've been at it for hours tweaking settings and Google'ing around to no avail.
In case someone like me will be looking for answer after all this time passed...
Problem is easy solved by installing wubi version of 32bit Ubuntu. It works fine on 64bit system. You only need to edit makefile so it knows where to look for the libraries provided.
I'm pretty sure that using a precompiled library for linux on macos, whatever the bitness, won't work (well, it is probably possible to cross-compile on MacOS for Linux and perhaps possible to run Linux executable in a compatibility box on MacOS, but that's quite different than what you are trying to do).
libnsl is a standard library on Linux (it provides some networking related functions)

Linking using g++ fails searching for -lstdc++

I'm trying to use someone else's Makefile to complile a very simple c++ library. The makefile is as follows:
JNIFLAGS=-O2 -pthread -I/usr/lib/jvm/java-6-sun/include -I/usr/lib/jvm/java-6-sun/include/linux
all:
rm -f ../dist/libUtils.so
g++ $(JNIFLAGS) -c -m32 -o com_markets_utils_dates_NativeTime.o com_markets_utils_dates_NativeTime.cpp
g++ $(JNIFLAGS) -c -m32 -o DateUtil.o DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libUtils.so DateUtil.cpp
g++ -pthread -m32 -shared -fPIC -o ../dist/libNativeTime.so DateUtil.o com_markets_utils_dates_NativeTime.o
This compiles fine, but the linker complains:
...
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.1/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
collect2: ld returned 1 exit status
make: *** [all] Error 1
FYI, I am on Ubuntu 9.10 64bit.
Posting for future reference, a solution I found was to install g++-multilib. I had the same incompatible problem relating to -lstdc++ on g++ version 4.6.1
On further probing: g++-multilib is a dummy package which installed g++4.6-multilib which in turn installed the appropriate libstdc++.so under the /usr/lib/gcc/x86_64-linux-gnu/4.6/32 folder.
Answering my own question:
Ths solution seems to be a bit of a hack, you need to create a symlink for the 32 bit version of the library (after installing the packages mentioned in #nos's answer):
$ sudo ln -s /usr/lib32/libstdc++.so.6 /usr/lib32/libstdc++.so
Once you've done this, the linker will automagically find the correct library to use.
It seems you're compiling a 32 bit library on a 64 bit machine, however a 32 bit version of libstdc++ is not present.
Try apt-get install ia32-libs libc6-i386 libc6-dev-i386 lib32gcc1 lib32stdc++6
(btw. you're producing a .so , you should specify -fPIC when compiling your .cpp files as well)

Resources