cmake not finding library needed for linking - oracle

I am converting a make file into cmake.
Make:
ORACLE = -L${ORACLE_HOME}/lib/ -lclntsh \
-I${ORACLE_HOME}/rdbms/public
CMAKE:
include_directories(${ORACLE_DIR}/include)
link_directories(${ORACLE_DIR}/lib)
project(DB_I)
add_executable(DB_I DB_I.c)
target_link_libraries(DB_I LINK_PUBLIC ${PROJECT_LINK_LIBS} -lclntsh)
install(TARGETS DB_I DESTINATION ${OPEN_FOX_BIN_DIR})
Error:
[ 53%] Linking C executable DB_I
/usr/bin/ld: cannot find -lclntsh
collect2: error: ld returned 1 exit status
I have ORACLE_HOME pointing to the directory where the files exist. The compiler is finding the OCI.H file it needs.
Directory structure...
ORACLE_HOME
include
oci.h
lib
libclntsh.so
I have even tried moving the libraries into the same directory as the source.
I even copied clntsh to /usr/bin.
What am I missing?
Thanks

You don't need the leading -l in the target_link_libraries
target_link_libraries(DB_I LINK_PUBLIC ${PROJECT_LINK_LIBS} clntsh)

Sorry
I just noticed the library file was a link. And the link was wrong.
I fixed that and all is good.
Thanks for your attention

The Problem is ORACLE_HOME is an environment variable.
In Make you get the value wich ${ORACLE_HOME} but in cmake you must write $ENV{ORACLE_HOME}
Also change your
link_directories(${ORACLE_DIR}/lib)
into
link_directories($ENV{ORACLE_DIR}/lib)

Related

Old lapack .dylib is being linked instead of the current version

I use lapack in an exact diagonalization program.
Using otool -L V3.e I am told that I have linked to the library "/opt/local/lob/lapack/liblapack.3.dylib". In the very same directory is the library "liblapack.3.8.0.dylib". The implication here is that the latter is a new version of lapack and is therefore desirable.
I can't figure out how to link to one over the other. My current compiler flags for linking to this library is:
-0fast -I$(DIR) -L$(DIR) -llapack
Where $(DIR) is the directory shown above.
I don't have admin permission but can easily ask the person in charge of the MacPorts. So if the its possible to remove one of those libraries I can make that happen.
EDIT: In response to Gavin Portwood.
... -L$(DIR) -llapack3.8
For this one all module files compiled well but the linker failed with the following error:
ld: library not found for -llapack3.8
collect2: error: ld returned 1 exit status
make: *** [V3] Error 1
I tried a variant with 3.8.0 at the end instead of 3.8 and got the same result.
... -L$(DIR) -l:liblapack.3.dylib
Slightly confused about this one since I don't want to use the this library. But with this one I was given the same error as above. If I change it to `l:liblapack.3.8.0.dylib' I get the same error.
... -L$(DIR) /opt/local/lob/lapack/liblapack.3.dylib
This last one didn't give me an error but a warning. The warning is as follows:
warning: /opt/local/lib/lapack/liblapack.3.8.0.dylib: linker input file unused because linking not done
Note that I did correct your typo. The program seems to have run correctly but when I ran otool -L <exe> I was linking to liblapack.3.dylib. Also, my compiler is gfortran.
EDIT2: Directory contents /opt/local/lib/lapack/
cmake libcblas.3.dylib liblapacke.3.8.0.dylib
libblas.3.8.0.dylib libcblas.dylib liblapacke.3.dylib
libblas.3.dylib liblapack.3.8.0.dylib liblapacke.dylib
libblas.dylib liblapack.3.dylib pkgconfig
libcblas.3.8.0.dylib liblapack.dylib
EDITFINAL Turns out the directories were soft linked. See Comments on Gavin's answer.
Depending on your compiler and version, link with one of the following:
... -L$(DIR) -llapack3.8.0
... -L$(DIR) -l:liblapack.3.8.0.dylib
... -L$(DIR) /opt/local/lob/lapack/liblapack.3.8.0.dylib

Linking ports libraries under FreeBSD

I have built some libraries (gtk3, qt5, ...) through the ports collection under FreeBSD 11.2. In order to test them I just built minimal examples. Each time the linker complains about not finding these libraries.
Correct me if I am wrong, but under FreeBSD, regular packages (those which are setup with pkg) are installed under /usr/include and /usr/lib, however ports lie, by default, under /usr/local/include and /usr/local/lib.
Is there a simple way to tell the compiler to search under these directories rather than having huge compilation commands with the -I and -L options?
Thank you for your answers.
Edit
Here is my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(gtk-test)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(GTK3 REQUIRED)
include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})
add_executable(gtk-test gtk-test.c)
target_link_libraries(gtk-test ${GTK3_LIBRARIES})
I have solved the dependencies issue by grabbing the following CMake script:
https://github.com/eiskaltdcpp/eiskaltdcpp/blob/master/cmake/FindGTK3.cmake
However, another problem has pop up:
[100%] Linking C executable gtk-test
/usr/lib/crt1.o: In function `_start':
crt1.c:(.text+0x91): undefined reference to `main'
collect2: error: ld returned 1 exit status
Edit
I am stupid, I even did not notice that there was no main function in the sample. It works fine except that, by default, CMake cannot locate GTK3 library and its dependencies.
Here is the content of my CMake config scripts:
Qt5
Qt53DQuick
Qt53DRender
Qt5DataVisualization
Qt5Location
Qt5OpenGLExtensions
Qt5QuickTest
Qt5SerialBus
Qt5UiPlugin
Qt5WebKit
Qt5XmlPatterns
Qt53DAnimation
Qt53DQuickAnimation
Qt5Bluetooth
Qt5Designer
Qt5Multimedia
Qt5Positioning
Qt5QuickWidgets
Qt5SerialPort
Qt5UiTools
Qt5WebKitWidgets
assimp-4.1
Qt53DCore
Qt53DQuickExtras
Qt5Charts
Qt5Gamepad
Qt5MultimediaWidgets
Qt5PrintSupport
Qt5Script
Qt5Sql
Qt5WebChannel
Qt5WebSockets
harfbuzz
Qt53DExtras
Qt53DQuickInput
Qt5Concurrent
Qt5Gui
Qt5Network
Qt5Qml
Qt5ScriptTools
Qt5Svg
Qt5WebEngine
Qt5Widgets
libxml2
Qt53DInput
Qt53DQuickRender
Qt5Core
Qt5Help
Qt5Nfc
Qt5Quick
Qt5Scxml
Qt5Test
Qt5WebEngineCore
Qt5X11Extras
Qt53DLogic
Qt53DQuickScene2D
Qt5DBus
Qt5LinguistTools
Qt5OpenGL
Qt5QuickControls2
Qt5Sensors
Qt5TextToSpeech
Qt5WebEngineWidgets
Qt5Xml

Weird behavior of gcc while linking BLAS library

I have ATLAS library "libatlas.so" in an unstandard directory "/opt/apps/gcc4_7/atlas/3.10.2/lib/"
I put the path along with other search paths in environment variable
LD_LIBRARY_PATH=/opt/apps/gcc4_7/atlas/3.10.2/lib:and_others
Then link my code with it as follow:
g++ mycode.o -L$LD_LIBRARY_PATH -latlas
It then say "ld: cannot find -latlas"
But if I add the path again as follow:
g++ mycode.o -L$LD_LIBRARY_PATH -L/opt/apps/gcc4_7/atlas/3.10.2/lib/ -latlas
I have no issues.
I cannot think of any reasons this could happen. Is it because the $LD_LIBRARY_PATH has too many paths in it?

/usr/bin/ld: cannot find -lnetcdf

I am facing a problem,
When I am using Makefile to install a software, I am getting this error
/usr/bin/ld: cannot find -lg2c
When I am searching libg2c
Its showing the path:
/home/guest/Downloads/mdsplus/math/libg2c.a
/home/initm03/Desktop/mdsplus/math/libg2c.a
/home/initm03/Downloads/mdsplus/math/libg2c.a
/usr/local/mdsplus/math/libg2c.a
Please so the needful if possible
The linker needs to know where to look for the library.
use the --library-path commandline switch or the LD_LIBRARY_PATH environment variable to specify the path of your libraries.
In the makefile, you'll need to tell the linker where to find libg2c;
Change
-lg2c
in the linker options in the makefile to;
-L/usr/local/mdsplus/math -lg2c
...and it should be able to find it and link correctly.

ld: After successful linking shared lib not found on execution

I am currently working on a simple data synchonizer in a mixture of Fortran and C/C++ by using OpenMPI libraries. The synchonizer compiles and links correctly, as far as I can see:
f95 -o fortran_mpi_test *.o -L/usr/lib/gcc/x86_64-redhat-linux/4.1.1/
-L/usr/lib64/openmpi/1.4-gcc/lib/ -lmpi -lmpi_cxx -lstdc++
But when I execute the resulting executable on the same machined I get an error stating that one of the shared libraries is not found. That is confirmed by ldd.
Nevertheless the missing library libmpi_cxx.so.0 is located in one of the specified folders.
Could anyone give me a hint what I could have done wrong?
Check your environment variables. If your LIBRARY_PATH, LD_LIBRARY_PATH or similar vars have gotten out of sync or set to silly values you might not be searching the same directories for static libraries as you do for dynamics.
Also check out the ld.so manpage

Resources