I've installed pbs-drmaa library, but I get an error while running a C program.
Here's the compilation, I've used -L and -I to indicate the proper folders for pbs-drmaa files. As it shows, there's no compilation error:
$ gcc teste_drmaa1.c -L /usr/lib/pbs-drmaa/lib -I /usr/lib/pbs-drmaa/include -ldrmaa -o teste_drmaa1
But when I try to run, I get an error:
$./teste_drmaa1
./teste_drmaa1: error while loading shared libraries: libdrmaa.so.1: cannot open shared object file: No such file or directory
But the file exists in the path given for -L:
ls /usr/lib/pbs-drmaa/lib
libdrmaa.so# libdrmaa.so.1# libdrmaa.so.1.0.10
What am I doing wrong?
Thanks in advance.
Solved running ldconfig.
Now compilation is:
gcc teste_drmaa1.c -ldrmaa -o teste_drmaa1
Related
I am trying to make a shared library for a particular problem I was working on. It has "point_sense.c" as the main file which uses functions defined in "createPolygon.c." The functions are declared in a header file "createPolygon.h."
To compile them, I used a makefile which looks like the following
all:point_sense
createPolygon.o:createPolygon.c
g++ -c -fpic createPolygon.c
libcreatePolygon.so:createPolygon.o
g++ -shared -o libcreatePolygon.so createPolygon.o
point_sense:point_sense.c libcreatePolygon.so
g++ -o point_sense -L~Desktop/Summer_2020_linux/tutorials/cpp_practise point_sense.c -lcreatePolygon
clean:
rm point_sense createPolygon.o libcreatePolygon.so
but when I make the file, it gives an output as
g++ -c -fpic createPolygon.c
g++ -shared -o libcreatePolygon.so createPolygon.o
g++ -o point_sense -L~Desktop/Summer_2020_linux/tutorials/cpp_practise point_sense.c -lcreatePolygon
/usr/bin/ld: cannot find -lcreatePolygon
collect2: error: ld returned 1 exit status
make: *** [makefile:10: point_sense] Error 1
Initially I thought this was some silly mistake, and to check I used
ld -L~/Desktop/Summer_2020_linux/tutorials/cpp_practise -lcreatePolygon -verbose
and after a long output I got (a few unimportant lines in the code are skipped in between)
ld: mode elf_x86_64
attempt to open ~/Desktop/Summer_2020_linux/tutorials/cpp_practise/libcreatePolygon.so failed
attempt to open ~/Desktop/Summer_2020_linux/tutorials/cpp_practise/libcreatePolygon.a failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libcreatePolygon.so failed
attempt to open /usr/local/lib/x86_64-linux-gnu/libcreatePolygon.a failed
.
.
.
ld: cannot find -lcreatePolygon
But when I try to open 'libcreatePolygon.so' directly, I am able to open it.
$ nano ~/Desktop/Summer_2020_linux/tutorials/cpp_practise/libcreatePolygon.so
There are several threads which explain the process of doing this, but I don't see what it is that I am doing wrong. Any help is appreciated.
I am using Ubuntu 20.04.1 LTS and g++ (Ubuntu 9.3.0-10ubuntu2) 9.3.0 .
I tried to reproduce the problem here, and this error message goes away if you put a space between the -L flag and the tilde character.
The reason is: if there is no space between -L and ~, the tilde character cannot be expanded to the home directory.
I am new to ubuntu and hence to make file. I have successfully created make file with folder structure. However, if I add the similar structure, I get an error.
I successfully executed make command and ran application with one main cpp file and two files (list_menu.cpp and list_menu.h ) in sub folder cpp11_and_cpp14_menu
folder structure looks exactly like below where cpp11_and_cpp14.cpp has the main function.
../advancedcppproject/
cpp11_and_cpp14.cpp
Makefile
../advancedcppproject/cpp11_and_cpp14_menu
list_menu.cpp
list_menu.h
../advancedcppproject/multi_threading_example
multi_threading.cpp
multi_threading.h
Make file contents are
cpp11_and_cpp14 : cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o
g++ cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o -o cpp11_and_cpp14
cpp11_and_cpp14.o : cpp11_and_cpp14.cpp ./cpp11_and_cpp14_menu/list_menu.h ./multi_threading_example/multi_threading.h
g++ -c cpp11_and_cpp14.cpp
./cpp11_and_cpp14_menu/list_menu.0 : ./cpp11_and_cpp14_menu/list_menu.cpp ./cpp11_and_cpp14_menu/list_menu.h
g++ -c ./cpp11_and_cpp14_menu/list_menu.cpp
./multi_threading_example/multi_threading.o : ./multi_threading_example/multi_threading.cpp ./multi_threading_example/multi_threading.h
g++ -c ./multi_threading_example/multi_threading.cpp
After executing make command, it fails with an error message
g++ -c ./multi_threading_example/multi_threading.cpp
g++ cpp11_and_cpp14.o ./multi_threading_example/multi_threading.o ./cpp11_and_cpp14_menu/list_menu.o -o cpp11_and_cpp14
g++: error: ./multi_threading_example/multi_threading.o: No such file or directory
Makefile:6: recipe for target 'cpp11_and_cpp14' failed
make: *** [cpp11_and_cpp14] Error 1
I expect multi_threading.o to be created under folder ../advancedcppproject/multi_threading_example. However multi_threading.o is created under ../advancedcppproject.
Where as list_menu.o is correctly created under ../advancedcppproject/cpp11_and_cpp14_menu.
What is wrong?
I am trying to compile main.c with a static library and header files on an Ubuntu server using gcc and ssh using Terminal on Mac. I uploaded the library file and specified it with -L option and specified the header files using the -I option.
I tried using:
gcc main.c -L/Libraries/lib/libRNA.a -lRNA -ILibraries/include/ViennaRNA
It comes out with:
/usr/bin/ld: cannot find -lRNA
collect2: error: ld returned 1 exit status
-L expects a directory as argument. You're passing the name of the library.
Just do:
gcc main.c -L/Libraries/lib -lRNA -ILibraries/include/ViennaRNA
or link with the absolute path of the .a file directly:
gcc main.c /Libraries/lib/libRNA.a -ILibraries/include/ViennaRNA
The -L option specifies a directory where the library file is.
The -L option to gcc (which gets actually passed to ld) is expecting a directory (in which further -l options are seeked).
The -I option is expecting a directory containing included header files.
So you want
gcc -Wall -g main.c -L/Libraries/lib/ -lRNA -ILibraries/include/ViennaRNA
You really want all warnings (-Wall) and debug information (-g) to be able to use the gdb debugger.
I will start by saying that I am new to gcc and makefiles. I have a .so file on the desktop (~/Desktop) called lib.so. I want to link my program (called myProgram) to it. What I wrote in my makefile is:
g++ myProgram.o -L ~/Desktop -l lib -o myProgram
When I run make I get an error:
/usr/bin/ld: cannot find -llib
I also tried -l lib.so and got the same error.
What is the correct way to link?
Two solutions:
Rename the file to libsomething.so, then use -l something. The linker automatically wraps the name with lib prefix and .so suffix (or .a suffix for static libraries).
Use the option -l :lib.so. When you prefix the name with :, the linker uses the name as given.
These are explained in the ld man page.
This is my first time trying to compile FORTRAN code using a makefile. The OS is Ubuntu 12.04 LTS 64 bit. I encountered the following errors:
gfortran -o przm3123.exe canopy.o chem.o cnfuns.o cropdate.o datemod.o debug.o debug_cn.o f2kcli.o floatcmp.o furrow.o general.o i_errchk.o infnan.o inivar.o ioluns.o iosubs.o lambertw.o m_readvars.o utils.o wind.o fcscnc.o przm3.o rsexec.o rsinp1.o rsinp2.o rsinp3.o rsmcar.o rsmisc.o rsprz1.o rsprz2.o rsprz3.o rsprzn.o rsutil.o rsvado.o -L ../libanne4.0/lib -lwdm -ladwdm -lutil
/usr/bin/ld: cannot find -lwdm
/usr/bin/ld: cannot find -ladwdm
collect2: ld returned 1 exit status
make: *** [przm3123.exe] Error 1
The key element in the makefile is:
przm2_LIBS = -L ../libanne4.0/lib -lwdm -ladwdm -lutil
Is there anything I can do to fix this error? Should I try other compilers?
As ../libanne4.0/lib is a relative path, you might try changing it into an absolute one.
Also you could check whether the linker process has the rights to access and read the libs.
Update: To have the linker find a library specified using the option -l<name> the name of the libray shall be lib<name>.[a|so] and the parameter to -L should point the path were the library is located.
-L needs to preceed it's -l option(s).
One could specify -l and/or -L multiple times.
There is something wrong with the name "adwdmlib.a". A linking flag "-l adwdm" will tell the compiler to expect a lib file with the name "libadwdm.a", not "adwdmlib.a". Is this helpful or relevant? If your library name is "adwdmlib.a", that is probably why your linker can't find it.