I have used this command.
libtool --mode=compile gcc -g -o -c foo.c
Actual output should be like this after the command:
$libtool --mode=compile gcc -g -O -c foo.c
mkdir .libs
gcc -g -O -c foo.c -fPIC -DPIC -o .libs/foo.o
gcc -g -O -c foo.c -o foo.o >/dev/null 2>&1
but observed output is
$libtool --mode=compile gcc -g -O -c foo.c
gcc -g -O -c foo.c -fPIC -DPIC -o .libs/foo.o
gcc -g -O -c foo.c -o foo.o >/dev/null 2>&1.
.libs directory is not creating. It there any changes i have to make
http://www.gnu.org/software/libtool/manual/html_node/Creating-object-files.html
On shared library systems, libtool automatically generates an additional PIC object by inserting the appropriate PIC generation flags into the compilation command:
burger$ libtool --mode=compile gcc -g -O -c foo.c
mkdir .libs
gcc -g -O -c foo.c -fPIC -DPIC -o .libs/foo.o
gcc -g -O -c foo.c -o foo.o >/dev/null 2>&1
burger$
Note that Libtool automatically created .libs directory upon its first execution, where PIC library object files will be stored.
Since ‘burger’ supports shared libraries, and requires PIC objects to build them, Libtool has compiled a PIC object this time, and made a note of it in the libtool object:
# foo.lo - a libtool object file
# Generated by ltmain.sh (GNU libtool) 2.4.2
#
# Please DO NOT delete this file!
# It is necessary for linking the library.
# Name of the PIC object.
pic_object='.libs/foo.o'
# Name of the non-PIC object.
non_pic_object='foo.o'
Notice that the second run of GCC has its output discarded. This is done so that compiler warnings aren't annoyingly duplicated. If you need to see both sets of warnings (you might have conditional code inside ‘#ifdef PIC’ for example), you can turn off suppression with the -no-suppress option to libtool's compile mode:
burger$ libtool --mode=compile gcc -no-suppress -g -O -c hello.c
gcc -g -O -c hello.c -fPIC -DPIC -o .libs/hello.o
gcc -g -O -c hello.c -o hello.o
burger$
I hope this would be helpful.
Thanks & Regards,
Alok
Related
I'm using curl in my code and running through Makefile. but while running with "make" command its giving error like "curl/curl.h: No such file or directory".
Here below is my makefile content.
CXX = /home/directory/Documents/xyz/l4t-gcc/bin/aarch64-buildroot-linux-gnu-cc
path = /home/directory/Documents/xyz/l4t-gcc/bin/
CFLAGS = -Wall
#INCLUDE = -I/usr/local/include -I/usr/include -Iinclude
#LDFLAGS = -L/usr/local/lib -I/usr/lib
LDLIBS = -lcurl
SOURCES = src/sms_wrapper.c src/twilio.c
OUT = bin/sms_wrapper
all: build
build: $(SOURCES)
$(CXX) -o $(OUT) $(CFLAGS) $(SOURCES) $(LDLIBS)
clean:
rm -rf bin/sms_wrapper
I install curl and added all things in Makefile which is needed for curl library.
Does anyone have any suggestions or idea for resolving this thing !
I am building foo.so and that depends on bar.so. They will both be installed in the same location /some/lib, with the RUNPATH set appropriately to /some/lib. But they are built from different directories.
I'm trying to build them like:
cd /tmp/bar
gcc -o bar.o -c bar.c
ld -Bshareable -o bar.so bar.o
cd /tmp/foo
gcc -o foo.o -c foo.c
ld -Bshareable -rpath /some/libs -o foo.so foo.o ../bar/bar.so
ldd foo.so
But the problem is that ldd shows ../bar/bar.so. I can fix it by doing:
cd /tmp/bar
gcc -o bar.o -c bar.c
ld -Bshareable -o bar.so bar.o
cd /tmp/foo
gcc -o foo.o -c foo.c
cp ../bar/bar.so .
ld -Bshareable -rpath /some/lib -o foo.so foo.o bar.so
ldd foo.so
Now the ldd just show plain bar.so, which is right. But is there a better way that doesn't require copying or symlinking bar.so just for the link step?
Solution:
ld -Bshareable -rpath /some/lib -L../bar -o foo.so foo.o -l:bar.so
works without needing to copy bar.so to the current directory.
I'm trying to install Git on a CentOS-7 server that I don't have root access to. I managed to get the source code for git, and did the following:
[som#jsClone git-1.8.3-rc1]make configure
<output omitted>
[som#jsClone git-1.8.3-rc1]./configure --prefix=$HOME/.local
<output omitted>
[som#jsClone git-1.8.3-rc1]$ make install
CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:19:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
make: *** [credential-store.o] Error 1
[som#jsClone git-1.8.3-rc1]$
So, to solve the error, I downloaded the source code for zlib, and extracted it to a folder $HOME/make_source/zlib. So currently it has the structure:
[som#jsClone ~]$ ls make_source/ -l
total 4820
drwxrwxr-x. 21 som som 12288 Jun 22 02:44 git-1.8.3-rc1
-rwxr-xr-x. 1 root root 4440451 Jun 22 02:13 git-1.8.3-rc1.tar.gz
lrwxrwxrwx. 1 som som 16 Jun 22 02:19 Shared -> /mnt/hgfs/Shared
drwxr-xr-x. 14 som som 4096 Jun 22 02:26 zlib-1.2.11
-rwxrwxr-x. 1 som som 467960 Jun 22 02:19 zlib-1.2.11.tar.xz
I installed zlib successfully with:
[som#jsClone zlib-1.2.11]make configure
<output omitted>
[som#jsClone zlib-1.2.11]$ ./configure --prefix=$HOME/.local
Checking for gcc...
Checking for shared library support...
Building shared library libz.so.1.2.11 with gcc.
Checking for size_t... Yes.
Checking for off64_t... Yes.
Checking for fseeko... Yes.
Checking for strerror... Yes.
Checking for unistd.h... Yes.
Checking for stdarg.h... Yes.
Checking whether to use vs[n]printf() or s[n]printf()... using vs[n]printf().
Checking for vsnprintf() in stdio.h... Yes.
Checking for return value of vsnprintf()... Yes.
Checking for attribute(visibility) support... Yes.
[som#jsClone zlib-1.2.11]$ make install
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o adler32.o adler32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o crc32.o crc32.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o deflate.o deflate.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o infback.o infback.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o inffast.o inffast.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o inflate.o inflate.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o inftrees.o inftrees.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o trees.o trees.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o zutil.o zutil.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o compress.o compress.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o uncompr.o uncompr.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzclose.o gzclose.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzlib.o gzlib.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzread.o gzread.c
gcc -O3 -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -c -o gzwrite.o gzwrite.c
ar rc libz.a adler32.o crc32.o deflate.o infback.o inffast.o inflate.o inftrees.o trees.o zutil.o compress.o uncompr.o gzclose.o gzlib.o gzread.o gzwrite.o
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/adler32.o adler32.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/crc32.o crc32.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/deflate.o deflate.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/infback.o infback.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/inffast.o inffast.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/inflate.o inflate.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/inftrees.o inftrees.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/trees.o trees.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/zutil.o zutil.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/compress.o compress.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/uncompr.o uncompr.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzclose.o gzclose.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzlib.o gzlib.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzread.o gzread.c
gcc -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -DPIC -c -o objs/gzwrite.o gzwrite.c
gcc -shared -Wl,-soname,libz.so.1,--version-script,zlib.map -O3 -fPIC -D_LARGEFILE64_SOURCE=1 -DHAVE_HIDDEN -o libz.so.1.2.11 adler32.lo crc32.lo deflate.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo zutil.lo compress.lo uncompr.lo gzclose.lo gzlib.lo gzread.lo gzwrite.lo -lc
rm -f libz.so libz.so.1
ln -s libz.so.1.2.11 libz.so
ln -s libz.so.1.2.11 libz.so.1
rm -f /home/som/.local/lib/libz.a
cp libz.a /home/som/.local/lib
chmod 644 /home/som/.local/lib/libz.a
cp libz.so.1.2.11 /home/som/.local/lib
chmod 755 /home/som/.local/lib/libz.so.1.2.11
rm -f /home/som/.local/share/man/man3/zlib.3
cp zlib.3 /home/som/.local/share/man/man3
chmod 644 /home/som/.local/share/man/man3/zlib.3
rm -f /home/som/.local/lib/pkgconfig/zlib.pc
cp zlib.pc /home/som/.local/lib/pkgconfig
chmod 644 /home/som/.local/lib/pkgconfig/zlib.pc
rm -f /home/som/.local/include/zlib.h /home/som/.local/include/zconf.h
cp zlib.h zconf.h /home/som/.local/include
chmod 644 /home/som/.local/include/zlib.h /home/som/.local/include/zconf.h
[som#jsClone zlib-1.2.11]$
The $HOME/.local has the structure:
[som#jsClone ~]$ tree $HOME/.local
/home/som/.local
├── bin
├── include
│ ├── zconf.h
│ └── zlib.h
├── lib
│ ├── libz.a
│ ├── libz.so -> libz.so.1.2.11
│ ├── libz.so.1 -> libz.so.1.2.11
│ ├── libz.so.1.2.11
│ └── pkgconfig
│ └── zlib.pc
└── share
└── man
└── man3
└── zlib.3
7 directories, 8 files
So now that zlib is installed, I tried to build git again, specifying the location of the zlib.h file, but it doesn't work.
[som#jsClone git-1.8.3-rc1]$ make
CC credential-store.o
In file included from credential-store.c:1:0:
cache.h:19:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
make: *** [credential-store.o] Error 1
How can I fix this?
I came across a very strange issue of makefile, here it is:
System: Linux CentOS 6
In the beginning, the name of makefile is “makefile”, its sample contents:
OPTFLAGS = -Wall -g -O
CXX = g++
INC = -I/usr/local/include -I/usr/include
LIBS = -L/usr/local/lib -L/usr/lib64
CXXFLAGS = $(OPTFLAGS) $(INC)
SOURCES = file1.cpp file2.cpp file3.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = mybin
$(EXECUTABLE): $(OBJECTS)
$(CXX) $(CXXFLAGS) $(INC) $(LIBS) $(OBJECTS) -o $#
file1.o : file1.cpp
file2.o : file2.cpp
file3.o : file3.cpp
.PHONY: clean
clean:
rm -f $(EXECUTABLE) *.o core*
I got following err after I ran “make”:
g++: file3.o: No such file or directory
I have a workaround to add a dummy file after file3:
dummy.o : dummy.cpp
This way I could build successfully.
And I know that I can delete all these lines:
file1.o : file1.cpp
file2.o : file2.cpp
file3.o : file3.cpp
let make to build using default settings, I could build successfully this way.
I also tried to just rename “makefile” to “Makefile”, and with following lines without dummy line:
file1.o : file1.cpp
file2.o : file2.cpp
file3.o : file3.cpp
To my surprise, I could build successfully this way.
Could anyone explain why I got error of “No such file or directory” for the last file3 in the beginning?
Following is the error output:
g++ -g -Wall -O -I/usr/local/include -I/usr/include -c -o file1.o file1.cpp
g++ -g -Wall -O -I/usr/local/include -I/usr/include -c -o file2.o file2.cpp
g++ -g -Wall -O -I/usr/local/include -I/usr/include -I/usr/local/include -I/usr/include -L/usr/local/lib -L/usr/lib64 -lsybdb file1.o file2.o file3.o -o mybin
g++: file3.o: No such file or directory
make: *** [mybin] Error 1
Following is the output after I added dummy line:
g++ -Wall -g -O -I/usr/local/include -I/usr/include -c -o file1.o file1.cpp
g++ -Wall -g -O -I/usr/local/include -I/usr/include -c -o file2.o file2.cpp
g++ -Wall -g -O -I/usr/local/include -I/usr/include -c -o file3.o file3.cpp
g++ -Wall -g -O -I/usr/local/include -I/usr/include -I/usr/local/include -I/usr/include -L/usr/local/lib -L/usr/lib64 -lsybdb file1.o file2.o file3.o -o mybin
I tried to rename "makefile" to "Makefile" again, and it doesn't work this time.
Ufffff!! Found your problem.
When you wrote
file1.o : file1.cpp
file2.o : file2.cpp
file3.o : file3.cpp
in your makefile a deamon came and introduced a TAB after the line file3.o : file3.cpp so make instead of taking implicit rule thought you are specifying explicit rule. For file1.o and file2.o it used implicit rule but for file3.o it assumed your are specifying explicit rule because of that TAB, but you had given it a blank TAB so file3.o was never built.
Now when you added dummy.o:dummy.cpp the TAB moved below that line so file3.o was compiled. When you were experimenting around you deleted that TAB that's why renaming makefile to Makefile seemed to work.
Just FYI: there is no difference between Makefile or makefile both are treated equally by make, except when both Makefile and makefile files are there in same folder and you give make then makefile is executed instead of Makefile
Even though I have linked -lrt in my Makefile, as you can see below, I am still getting undefined reference to 'mq_open'. Please help!
all:get1 iserv1
get: get1.c
gcc -Wall -o get1 get1.c -lrt
iserv: iserv1.c
gcc -Wall -o iserv1 iserv1.c -lrt
clean:
rm -fr *~ get1 iserv1
Note -lrt should be at end not inbetween.
Your makefile is wrong
all:get1 iserv1
get: get1.c
gcc -Wall -o get1 get1.c -lrt
all has a prerequisite of get1 and iserv1. But you created a get target and an iserv target. So e.g. get1 will be compiled with the default make rules, which does not include -lrt (this should show if you look at the gcc commands that actually are executed.)
Your makefile should like like this:
all:get1 iserv1
get1: get1.c
gcc -Wall -o get1 get1.c -lrt
iserv1: iserv1.c
gcc -Wall -o iserv1 iserv1.c -lrt
clean:
rm -fr *~ get1 iserv1