Find the path to a library when using headless linux image - linux

Hi I'm connected to parallella board , using only UART, I'm written and executing codes using only GNU bash, and I don't have a desktop. only that terminal connection
I'm using DevIL library in a C code, and i receive undefined reference toilInit'` etc..
so I should tell where is the path to DevIL library, what are the GNU bash instructions in order to find the /path/to/DevIL/lib/dir and DevIL lib name, I try find DevIL , and i receive no such file or directory

Try
find / -name libname
where libname is the name of your library. This will return all paths that contain a file with the name libname anywhere in your system. If you have a rough idea of the location, use that path instead of the system root / as this will make the command run faster (When called as above the first argument is telling the find command what directory to search under).
Libraries usually start with libxyz, so perhaps you should check the name as DevIL does not adhere to this convention.
You must know the library name since you will need to pass its name and location as a link option to your C compiler at some point.

Related

Which library does `Cmake` prefer to link to when invoking `target_link_libraries(target_name, library_name_without_postfix)`?

Both static and shared versions of a specific library are in the same folder, then which library does Cmake prefer to link to when invoking target_link_libraries(target_name, library_name_without_postfix)?
Why?
If target_link_libraries takes the library name in the 2nd parameter, it entirely depends on the linker. In your case, the link line will be translated to
-llibrary_name_without_postfix.
In this case, it will be searched in the standard path like, LD_LIBRARY_PATH, /etc/ld.so.conf or in the system path.
Since you didn't say anything about the location, I assume the library lives in the current build directory. And you have a command somewhere including the current build directory in the linker path using link_directories. In this case, the default link is dynamic.

Unable to set environment variable for ctypes (c library for python)

I need some third-party c library to be imported into a low-level module. I'm following these instructions. It says that find_library() should help me find such a lib, excluding any lib prefix and .so suffix.
#next 2 lines just to test
test =find_library('spcm_linux')
print(test)
#this line below is the actual code
spcmDll = cdll.LoadLibrary("libspcm_linux.so")
Returns:
None
OSError: spcm_linux.so: cannot open shared object file: No such file or directory
My library lives at:
/usr/lib/gcc/x86_64-linux-gnu/libspcm_linux.so
Reading about find_library() from the docs, it tells me that I can set an environment variable to add an environement variable (LD_LIBRARY_PATH). So in /etc/environement I have:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:"
PYTHONPATH="/home/fv/.local/lib/python3.6/site-packages"
LD_LIBRARY_PATH="/usr/lib/gcc/x86_64-linux-gnu"
I restart, try and it still doesn't work (same error message).
Any other way to "find" my library? Could put it in my program.py directory directly & import it some other way?
EDIT:
However, it does find libgomp.so.1, which is in the exact same folder as the library I'm trying to load. If that helps...
Turns out the root of the issue was rights.
Rights to the libspcm_linux.so lib weren't set properly and thus the script had no access rights to it.
However, the error that popped up was still about No such file or directory. I presume this is because it's a C library, which ctypes tried to load. It couldn't load it (because it didn't have the rights to it) however apparently it didn't see it fit to propagate the error (or couldn't because of some technicalities of how C code is loaded, perhaps).
Therefore from it's point of view, it couldn't load the requested library, and told me so - "No such file or..." even if this hide the real cause of the problem.

NODE_SHARED_MODE and __POSIX__

What is the role of NODE_SHARED_MODE and POSIX macros in node.js source code ?
In which file they are defined?
These are present in node_main.cc in nodejs src directory
You can use GitHub's search feature (or grep in a local checkout) to search through Node.js's source code:
https://github.com/nodejs/node/search?q=NODE_SHARED_MODE
https://github.com/nodejs/node/search?q=POSIX
And you will find that both symbols are defined in node.gypi. From reading the surrounding code in that file, you can also deduce the conditions under which they are defined.

Link to NAG library with -lnag

I'm trying to compile my first program which uses the NAG library, the following:
program naginfo
use nag_f77_a_chapter
implicit none
write(*,*) 'Calling NAG identification routine'
write(*,*)
call a00aaf
end program naginfo
This is copied from the tutorial and they suggest to compile it with the following statement:
f95 -o naginfo naginfo.f90 -lnag
and they suppose that this -lnag drives the linker to NAG library, but then I find this error:
Fatal Error: Can't open module file ‘nag_f77_a_chapter.mod’ for reading at (1): The directory does not exist
I've tried changing the directory of the NAG files to help the linker find it.
How do I get this to compile and link?
This is just a long explanation of francescalus's comment.
The flag -lnag only adds the library code to the already compiled program when linking all compiled pieces together. It has no effect during compilation and hence no effect on the error message you see.
The compiler must see the information about the NAG library modules. That is usually stored in module files with the .mod extension. Compilers normally only search for these in the current directory or in the system's include directories.
You can instruct the compiler to search in a different directory by using a special compiler flag. It may differ between different compilers, but is typically -I followed by the directory where the library stores its .mod files.
Be advised that the .mod files in the library are only compatible with the same compiler that was used to create them by the library vendor.

C++ Creating a standalone library in linux and using it in another program

I'm trying to create a shared library for Linux such that:
other programs can use its functions and its objects
the code is not visible to final user
What i did is create a shared library with Eclipse. This library uses pthreads.
I generated .so and .lib. The .lib is in LIBRARY/Lib while the .so is in LIBRARY/Release.
Then i created another project which should use this library and i gave the path of the .lib file and the path of the .h file which only contains the inclusions of all the necessary .h of the library.
All seems working but when i run the program it crashes. When debugging it I receive the following message:
Can't find a source file at "pthread_mutex_lock.c"
Locate the file or edit the source lookup path to include its location.
What's wrong? Can someone help me please?
EDIT: I changed nothing and now I have a different error, some lines before the previous:
Can't find a source file at "random.c"
Locate the file or edit the source lookup path to include its location.
other programs can use its functions and its objects
the code is not visible to final user
These two goals directly contradict each other, and achieving both at the same time is impossible on Linux.
If some program can use your library, then I can write a new program that can do so as well.

Resources