Kdevelop4 path to library binaries - kdevelop

I'm having problem reported as below while trying to execute it. Where should I go to let it know where to find the .so lib which is under ${HOME}/projects/OpenImageIO/dist/linux64/lib?
Starting: /home/chaoren/Dropbox/hw2/hw2_3
/home/chaoren/Dropbox/hw2/hw2_3: error while loading shared libraries: libOpenImageIO.so.1.2: cannot open shared object file: No such file or directory
I built this project by importing my Makefile
OFILES = Matrix.o LinearAlgebra.o PerlinNoise.o Camera.o OIIOFiles.o Image.o Utilities.o Grid.o SparceGrid.o VolumeOperations.o Ray.o Face.o Line.o Lights.o Group.o PolySurf.o File.o OBJFile.o Vector.o
AFILES = $(OFILES)
ROOTDIR = .
LIB = $(ROOTDIR)/libVR.a
LINKS = Magick++-config --cppflags --cxxflags --ldflags --libs -lm -lOpenImageIO -L/usr/local/lib -L${HOME}/projects/OpenImageIO/dist/linux64/lib
INCLUDES = Magick++-config --cppflags --cxxflags -I${HOME}/projects/OpenImageIO/dist/linux64/include
CXX = g++ -Wall -g -O2 -D_THREAD_SAFE -pthread -fopenmp
.C.o:
$(CXX) -c $(INCLUDES) $<
all: $(AFILES)
ar rv $(LIB) $?
hw2_1: hw2_1.C
$(CXX) hw2_1.C $(INCLUDES) $(LIB) $(LINKS) -o hw2_1
hw2_2: hw2_2.C
$(CXX) hw2_2.C $(INCLUDES) $(LIB) $(LINKS) -o hw2_2
hw2_3: hw2_3.C
$(CXX) hw2_3.C $(INCLUDES) $(LIB) $(LINKS) -o hw2_3
noiseimage: noiseimage.C
$(CXX) noiseimage.C $(INCLUDES) $(LIB) $(LINKS) -o noiseimage
clean:
rm -f *.o *.gch core $(LIB) vr vrppm *~ vRender hw2_1 hw_2 hw2_3

KDevelop4 uses CMake as its default build system. In CMake all libraries and other program elements are identified in special file (CMakeLists.txt). That file then becomes the basis of the make file that actually builds the executable.

Related

"clang: error: cannot specify -o when generating multiple output files" fix

I'm trying to compile my C project using clang (I'm on MacOS Monterry) and a Makefile, but I keep getting the same error from clang in the command line:
> make
gcc -c src/ji.c src/main.c -o src/ji.o
clang: error: cannot specify -o when generating multiple output files
make: *** [src/ji.o] Error 1
These are the only files I have in the project so far:
src/main.c
src/ji.c
include/ji.h
The Makefile looks like this:
cc = gcc
src = $(wildcard src/*.c)
obj = $(src:.c=.o)
exec = ji
$(exec): $(obj)
$(cc) -Iinclude $< -o build/$#
%.o: %.c
$(cc) -c $(src) -o $#
clean:
-rm src/*.o
-rm ji
From YouTube videos I've seen, this should be the ideal Makefile for the project but no matter what I change I get the error.
There are a few issues:
-Iinclude needs to be on the %.o: %.c rule command
In %.o: %.c, we don't want $(src) but rather $<
We want patsubst to get the .o list obj
The $(exec) target doesn't match the -o option
The clean doesn't match the placement of the executable
Here's a refactored version (e.g. one way to do this--there are others):
cc = gcc
src = $(wildcard src/*.c)
obj = $(patsubst %.c,%.o,$(src))
exec = build/ji
$(exec): $(obj)
mkdir -p build
$(cc) $^ -o $#
%.o: %.c
$(cc) -c $< -o $# -Iinclude
clean:
rm -f src/*.o
rm -fr build
Here's the output of make:
gcc -c src/ji.c -o src/ji.o -Iinclude
gcc -c src/main.c -o src/main.o -Iinclude
mkdir -p build
gcc src/ji.o src/main.o -o build/ji
Here's the output of make clean:
rm -f src/*.o
rm -fr build

makefile exit with no reason when compile .pc and .c at the same time. very strange

I am using pro*c in AIX,I want make my .pc file compile to a .so libary. And link it. This is my directory:
ls
connect.pc func.c get_log.pc main.c makefile sql_err.pc
This is my makefile:
#Makefile
CC = cc -g -brtl
CFLAGS = -g -c
ESQL = proc
RM = rm -f
MYHOME = /home/xxx
OBJ = main.o func.o
LIBOBJ = get_log.o connect.o sql_err.o
DBINC = -I$(ORACLE_HOME)/precomp/public
DBLIB = -L$(ORACLE_HOME)/lib -lclntsh
INCLUDE = -I$(MYHOME)/include
.SUFFIXES: .pc .c .o
.pc.o:
$(ESQL) include=$(MYHOME)/include iname=$*.pc
$(CC) -o $*.o $(CFLAGS) $*.c $(INCLUDE) $(DBINC) $(DBLIB)
$(RM) $*.c
$(RM) $*.lis
libmydb.so:$(LIBOBJ)
$(CC) -qmkshrobj -o $# $(LIBOBJ) $(DBLIB)
mv $# $(MYHOME)/lib
query:$(OBJ)
cc -o $# $(OBJ) -L$(MYHOME)/lib -lmydb
mv $# $(MYHOME)/bin
func.o:func.c
$(CC) -c $(CFLAGS) $< $(INCLUDE)
main.o:main.c
$(CC) -c $(CFLAGS) $< $(INCLUDE)
clean:
rm -f *.o *.lis
when I make I get this:
.......
cc -g -brtl -o sql_err.o -g -c sql_err.c -I/home/xxx/include -I/oracle/product/10.2.0/precomp/public -L/oracle/product/10.2.0/lib -lclntsh
rm -f sql_err.c
rm -f sql_err.lis
cc -g -brtl -qmkshrobj -o libmydb.so get_log.o connect.o sql_err.o -L/oracle/product/10.2.0/lib -lclntsh
mv libmydb.so /home/xxxlib
when it done mv libmydb.so ,it exit!!!without wrong message.why?? I also need my .c to compile to .o and finally to an executable file query link libmydb.so.
when I change the squeuce like this put .c.o before .pc.o:
query:$(OBJ)
cc -o $# $(OBJ) -L$(MYHOME)/lib -lmydb
mv $# $(MYHOME)/bin
func.o:func.c
$(CC) -c $(CFLAGS) $< $(INCLUDE)
main.o:main.c
$(CC) -c $(CFLAGS) $< $(INCLUDE)
.pc.o:
$(ESQL) include=$(MYHOME)/include iname=$*.pc
$(CC) -o $*.o $(CFLAGS) $*.c $(INCLUDE) $(DBINC) $(DBLIB)
$(RM) $*.c
$(RM) $*.lis
libmydb.so:$(LIBOBJ)
$(CC) -qmkshrobj -o $# $(LIBOBJ) $(DBLIB)
mv $# $(MYHOME)/lib
it give this message,although I have libmydb.so last step:
prepaid(wmfe)/home/xxx/src>make
cc -g -brtl -c -g -c main.c -I/home/xxx/include
cc -g -brtl -c -g -c func.c -I/home/xxx/include
cc -o query main.o func.o -L/home/xxx/lib -lmydb
ld: 0706-006 Cannot find or open library file: -l mydb
ld:open(): A file or directory in the path name does not exist.
make: 1254-004 The error code from the last command is 255.
Stop.
I can't handle this ,very strange,Help!!
By default make will make the first rule in your makefile, but it must not start with a dot. So the default rule in your makefile is libmydb.so and that is being built.
That rule is only dependent on the LIBOBJ and OBJ is not a dependency so it doesn't care about those. It doesn't exit with no reason, it exits because it has done the job you defined for it. There is no error to report.
If you change the order then the default rule is changed and it tries to compile query. This has no dependencies to the library, so it doesn't try to compile that.
If you want to compile everything you should have, for example, a rule all that lists the dependencies. In this case probably libmydb.so and query at least, in correct order. If this is the first rule it will be the default and your compilation will succeed.

Link .so file into an executable file

I have object code that I have compiled using -fPIC switch in clang that also used the -shared switch. I have then linked all of these into a single .so shared object. Now I want to link this into a single executable file, I'm told by the man page that I should be able to do this using the
ld command and the -l switch. But when I do this, I get the following error:
ld -r -L./ -l:libmymath.so simpleone
ld: attempted static link of dynamic object `libmymath.so'
make: *** [simpleone] Error 1
I have tried doing the same thing with the -dy switch, but it gives me the same error.
I really don't understand why this wouldn't be working.
Here is the makefile I am using to do all of this.
CC= clang
LD= ld -r
CFLAGS= -std=gnu99 -g -Oz -c
CSECFL= -fPIC -I -L
CFLAG3= -shared
RM= /bin/rm -f
OBJ= math.o my*.o
SO= libmymath.so
all: math my_add my_mul
math: math.c
$(CC) $(CFLAGS) $#.c $(CSECFL)
my_add: my_add.c
$(CC) $(CFLAGS) $#.c $(CSECFL)
my_mul: my_mul.c
$(CC) $(CFLAGS) $#.c $(CSECFL)
simplemath: $(OBJ)
$(CC) $(OBJ) -o $#
simplemath.o: $(OBJ)
$(LD) $(OBJ) -o $#
lib1: my_add.o
$(CC) $(CFLAG3) my_add.o -o $(SO)
lib2: $(OBJ)
$(CC) $(CFLAG3) my_mul.o -o $(SO)
lib3: $(OBJ)
$(CC) $(CFLAG3) math.o -o $(SO)
simpleone: $(OBJ)
$(LD) -L./ -l:libmymath.so $#
clean:
$(RM) *.o simplemath* *.t $(SO)
You need to link the objects (*.o) into a static executable, not the shared lib (.so) .so can be opened by the run-time dynamic linker or via a dlopen() call.

Unable to link against BFD [duplicate]

This question already has answers here:
Trying to include a library, but keep getting 'undefined reference to' messages
(3 answers)
Closed 8 years ago.
I am trying to include this file in my project: http://cairo.sourcearchive.com/documentation/1.9.4/backtrace-symbols_8c-source.html
But it requires linking against BFD. I have both binutils and binutils-devel installed. I have tried linking with -lbfd as well as directly to /usr/lib64/libbfd.so and /usr/lib64/libbfd.a (which both do exist). I also tried searching pkg-config to see if there was a different flag I should be using, but there is no reference to BFD or binutils in pkg-config.
No matter what I've tried I get the following errors:
undefined reference to 'bfd_init'
undefined reference to 'bfd_openr'
undefined reference to 'bfd_check_format'
undefined reference to 'bfd_checkformat_matches'
undefined reference to 'bfd_close'
undefined reference to 'bfd_map_over_sections'
First I am compiling my logger and the backtrace-symbols.c file I linked to above (as the logger is where I intend to use this for printing traces). Then I am linking those two object files together into a combined object file:
CC = clang
CFLAGS = -g -Wall -c
SOURCE = simplog.c
OBJ = simplog.o, simplog-temp.o, backtrace-symbols.o
all:
$(CC) $(CFLAGS) $(SOURCE); mv simplog.o simplog-temp.o; \
$(CC) -ansi $(CFLAGS) backtrace-symbols.c; \
ld -r simplog-temp.o backtrace-symbols.o -o simplog.o
clean:
rm -f $(OBJ)
Then I am linking this object file into my main project:
CC= clang++
PROG= ./bin/chiplus8
OBJS= ./src/main.o ./src/Chip8.o ./src/EmuCPU.o ./src/SimpleLogger/simplog.o
LIBS=
CXXFLAGS= -g -Wall -std=c++11 $(shell pkg-config --cflags ${LIBS})
LDFLAGS= $(shell pkg-config --static --libs ${LIBS})
all: logger $(PROG)
$(PROG): $(OBJS)
mkdir -p ./bin/
$(CC) -g -rdynamic -o $(PROG) $(LDFLAGS) -lbfd -liberty $(OBJS)
rm -f $(OBJS)
logger:
cd ./src/SimpleLogger; make clean all
clean:
rm -f $(PROG) $(OBJS)
I'm really not sure what I need to do to get this to link properly anymore. Is there something I'm missing?
Change:
$(PROG): $(OBJS)
mkdir -p ./bin/
$(CC) -g -rdynamic -o $(PROG) $(LDFLAGS) -lbfd -liberty $(OBJS)
rm -f $(OBJS)
To this:
$(PROG): $(OBJS)
mkdir -p ./bin/
$(CC) -g -rdynamic -o $(PROG) $(LDFLAGS) $(OBJS) -lbfd -liberty
rm -f $(OBJS)
Object files have to be placed before libraries with the compilation command. See this question.

What is the proper way to create library files with a Makefile? [C]

I am making my first Makefile for a simple shell system. I need to make library files but for some reason the library section is not working out. In the error message it says the library files do no exist (obviously).
Am I missing something obvious that could fix this? Also, is there any other way I can make this Makefile more efficient?
# Beginning of Makefile
OBJS = obj/shutil.o obj/parser.o obj/sshell.o obj/history.o obj/hash_table.o obj/variables.o
HEADER_FILES = include/shell.h include/parser.h include/history.h include/hash_table.h include/variables.h
EXECUTABLE = sshell
LIBS = lib/libshell.so lib/libparser.so lib/libhistory.so lib/libhash_table.so lib/libvariables.so
LIBCFLAGS = $(CFLAGS) -D_REENTRANT -fPIC
CFLAGS = -Wall
CC = gcc
# End of configuration options
#What needs to be built to make all files and dependencies
all: $(EXECUTABLE)
#Create the main executable
$(EXECUTABLE): $(OBJS) $(LIBS)
$(CC) -o $(EXECUTABLE) obj/sshell.o -Llib -lparser -lshell -lhistory -lhash_table -lvariables
#Create the library files
$(LIBS): $(OBJS)
$(CC) $(LIBCFLAGS) -shared -o $(LIBS) $(OBJS)
#Recursively build object files
obj/%.o: src/%.c
$(CC) $(CFLAGS) -I./include/ -c $< -o $#
#Define dependencies for objects based on header files
#We are overly conservative here, parser.o should depend on parser.h only
$(OBJS) : $(HEADER_FILES)
clean:
-rm -f $(EXECUTABLE) obj/*.o lib/*.so lib/*.a
-rm -f .sshell_history.txt
run: $(EXECUTABLE)
(export LD_LIBRARY_PATH=lib; ./$(EXECUTABLE))
# End of Makefile
Thanks!
-Lily Banks
Edit:
Before I tried to change it, here is what I had with regards to library files.
$(LIBS): $(OBJS)
$(CC) -shared -o lib/libparser.a obj/parser.o
$(CC) -shared -o lib/libshell.a obj/shutil.o
$(CC) -shared -o lib/libhistory.a obj/history.o
$(CC) -shared -o lib/libhash_table.a obj/hash_table.o
$(CC) -shared -o lib/libvariables.a obj/variables.o
The problem with this was that it compiled each file five times which is not efficient at all. So what I was trying to do was do it all in one go.
Edit2:
#Create the library files
lib/libparser.so: obj/parser.o
$(CC) $(LIBFLAGS) -shared lib/libparser.a -o $#
lib/libshell.so: obj/shutil.o
$(CC) $(LIBFLAGS) -shared lib/libshell.a -o $#
lib/libhistory.so: obj/history.o
$(CC) $(LIBFLAGS) -shared lib/libhistory.a -o $#
lib/libhash_table.so: obj/hash_table.o
$(CC) $(LIBFLAGS) -shared lib/libhash_table.a -o $#
lib/variables.so: obj/variables.o
$(CC) $(LIBFLAGS) -shared lib/libvariables.a -o $#
Unfortunately, here is the error I am getting:
make: *** No rule to make target `lib/libvariables.so', needed by `sshell'. Stop.
Thoughts?
Edit3:
#Create the library files
lib/libparser.so: obj/parser.o
$(CC) $(LIBFLAGS) -shared $^ -o lib/libparser.a
lib/libshell.so: obj/shutil.o
$(CC) $(LIBFLAGS) -shared $^ -o lib/libshell.a
lib/libhistory.so: obj/history.o
$(CC) $(LIBFLAGS) -shared $^ -o lib/libhistory.a
lib/libhash_table.so: obj/hash_table.o
$(CC) $(LIBFLAGS) -shared $^ -o lib/libhash_table.a
lib/libvariables.so: obj/variables.o
$(CC) $(LIBFLAGS) -shared $^ -o lib/libvariables.a
This works but is there anything else I need to change? Thanks
You need one set of object files for each library. And the -o flag only takes one argument which is the output file, you are trying to output all the library files which you cannot do with one invocation of gcc.
You need to do something like:
lib/libshell.so: obj/sshell.o
$(CC) $(LIBFLAGS) -shared obj/sshell.o -o lib/libshell.so
lib/libparser.so: obj/parser.o
$(CC) $(LIBFLAGS) -shared obj/parser.o -o lib/libparser.so
for each of the libraries.
This line is completely wrong:
$(LIBS): $(OBJS)
$(CC) $(LIBCFLAGS) -shared -o $(LIBS) $(OBJS)
If you expanded all the variables, this line would look like this (adding line breaks for clarity):
lib/libshell.so lib/libparser.so lib/libhistory.so lib/libhash_table.so lib/libvariables.so: \
obj/shutil.o obj/parser.o obj/sshell.o obj/history.o obj/hash_table.o obj/variables.o
gcc -Wall -D_REENTRANT -fPIC -shared -o lib/libshell.so lib/libparser.so lib/libhistory.so \
lib/libhash_table.so lib/libvariables.so obj/shutil.o obj/parser.o obj/sshell.o obj/history.o \
obj/hash_table.o obj/variables.o
Which, it should be clear, is very not right. It's so not right I can't even really tell what you're trying to accomplish. Do you really want to create one shared library for every .o file, where each shared library contains a single .o? If so why are you trying to link both the .o files AND the shared libraries into a single executable?
If you explain what you are really trying to do, at a higher level, we can help.

Resources