Buildroot installed libraries not appearing in target - package

I'm working on a buildroot-based linux for my actual project. I need to add the protobuf-c library and found that the library files, .a and .la, dissapear from the target directory after the "Finalizing target" step in buildroot, since it executes a command to arase all .a and .la files from target/usr/lib and target/lib, so they are empty on the target. Obviously after loading on the target files are still missing.
Can anyone help me on how I can find those files or how can I fix this?
I've tried installing other libraries from the buildroot menuconfig and the same happens, files are installd in /usr/lib directory, but at the end after the "Finalizing target" step they dissapear.
Thanks in advance

Buildroot will typically strip and install the shared libraries which end in .so
The static library ending in .a can be installed by implementing a post install hook in your package makefile. This hook looks like the following for an example package called "pack". In this case the following would be put into the pack.mk makefile :
define PACK_INSTALL_MOD
$(INSTALL) -D -m 755 $(#D)/.libs/libpack.a $(TARGET_DIR)/usr/lib/
endef
PACK_POST_INSTALL_TARGET_HOOKS += PACK_INSTALL_MOD

Related

How do I ask CMake to copy include directory while running "cmake install"?

Previously, I'm looking for this kind of question but none of them are working as example this thread and this one.
Currently, I'm creating a C library which supposed to outputs a shared library (*.so or *.dll) file and multiple *.h files in a ./include directory. The shared library is successfully built and installed to /usr/local/lib. However, I have no idea how do I tell CMake to copy *.h files to the correct destination as below.
In POSIX: /usr/local/include
In Windows: C:\<Compiler Path>\include
I know I could workaround this by copying those *.h with Python script or using if-else logic on CMake. But at least tell me if there is a feature in CMake for doing that thing. Thanks!
Here's my CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project (
learn_c_library
VERSION 1.0.0
LANGUAGES C
)
# Specify CMake build and output directory
set(CMAKE_BINARY_DIR "${PROJECT_SOURCE_DIR}/.cmake")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/out")
# Use every .c file inside ./src
file(GLOB_RECURSE MY_SOURCE_PATH "src/*")
add_library(
${PROJECT_NAME} SHARED
${MY_SOURCE_PATH}
)
include_directories(
${PROJECT_NAME}
"include/"
)
# Allows "make install" to install shared library
install(TARGETS ${PROJECT_NAME})
This answer improves on your answer:
cmake_minimum_required(VERSION 3.14)
# ...
include(GNUInstallDirs)
install(DIRECTORY "include/"
TYPE INCLUDE
COMPONENT MyProj_Development)
The GNUInstallDirs module provides standard configuration points for customizing a project's install layout. These variables should essentially always be used instead of hardcoding path/directory names.
The TYPE INCLUDE argument to install() was introduced in CMake 3.14 and uses GNUInstallDirs's CMAKE_INSTALL_INCLUDEDIR variable to determine the destination.
Finally, and especially if your project is a library, all your install() rules should be given a COMPONENT argument to allow splitting files between runtime and development packages (and potentially others like documentation and architecture-independent data files).
After days of fiddling CMake, finally I found the solution!
Let's assume you store your public *.h inside ./include directory, then here's the syntax for installing your *.h files to your machine:
install(
DIRECTORY
"include/" # Your global headers location in the project
DESTINATION
include # This is your system's default "include" location
)
I got the solution from here with usr/myproject replaced to be include

Using protoc inside CMakeLists from a non-standard directory gives "cannot open shared object file: No such file or directory" error

I have a C application using CMake to generate Makefiles on Linux. The application contains .c as well as .proto files. Now I need to genearte .pb-c.c and .pb-c.h using protoc command in the CMakeLists.txt so that when I do cmake . the cmake generates the corresponding .pb-c and .pb-h. The protoc is used as:
execute_process(COMMAND bash -c "${PROTOC_PATH} --c_out=${CMAKE_CURRENT_SOURCE_DIR}/ --proto_path=${PROTO_DIR}/ ${PROTO_DIR}/*.proto")
The problem is that my protoc binary and related .so file is not in /usr/bin and /usr/lib or /usr/local/bin and /usr/local/lib. They are in a directory inside the project - $HOME/project-name/dependencies/bin/protoc and $HOME/project-name/dependencies/lib/libprotobuf.so.12
Due to this I am getting error - error while loading shared libraries: libprotobuf.so.12: cannot open shared object file: No such file or directory
But if I give the command as
execute_process(COMMAND bash -c "protoc--c_out=${CMAKE_CURRENT_SOURCE_DIR}/ --proto_path=${PROTO_DIR}/ ${PROTO_DIR}/*.proto") and run cmake . then it works fine as linker is able to get the .so file from /usr/lib
Mentioned below is a part of my CMakeLists.txt file
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${PROTOC_LIB_PATH} -L${PROTOC_LIB_PATH} -lprotobuf")
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-rpath=${PROTOC_LIB_PATH} -L${PROTOC_LIB_PATH} -lprotobuf")
execute_process(COMMAND bash -c "${PROTOC_PATH} --c_out=${CMAKE_CURRENT_SOURCE_DIR}/ --proto_path=${PROTO_DIR}/ ${PROTO_DIR}/*.proto")
But it's not working due to aforementioned error.
Also for those who might say it's a duplicate I have looked into and tried the following SO questions:
Turning on linker flags with CMake
I don't understand -Wl,-rpath -Wl,
CMake link to external library
Does cmake have something like target_link_options?
CMAKE RPATH not working - could not find shared object file
https://serverfault.com/q/279068/435497
How to add linker flag for libraries with CMake?
https://serverfault.com/a/926072/435497
If you do not have a special use case, you do not need to call protoc yourself. Let CMake do this for you.
Have a look at: https://cmake.org/cmake/help/v3.16/module/FindProtobuf.html
and Cmake : find protobuf package in custom directory
I found this link which has a script showing how to create a PROTOBUF_GENERATE_C function which can then be used to generate the .pb-c abd .pb-h files.
From the above script I got the idea to make use of find_program which is similar to find_library in a way that it lets you pass the PATHS/PATH option so that CMake looks for the required program in the mentioned path.

How to check C libraries installed without root access?

I am working on a school project in a limited environment (archlinux) where I don't have root access. The subject says that I am allowed to use all libraries that are already installed. I am coding in C using gcc.
How to get a list of all those libraries ?
For those libraries managed by the pkg-config utility, the following command will show all installed libraries:
pkg-config --list-all | less
However, not all libraries are so managed so you may be forced to go through the /usr/lib and /usr/local/lib directories.
As noted, not all libraries necessarily use pkg-config. Given that this is ArchLinux, as a fallback you could learn to use the package manager, to list the installed packages. That is called pacman.
Anything that is installed as such on ArchLinux would be part of a package.
The query options can show you all of the files installed for given packages:
To list all files for a given package, use pacman -Qlpackage_name
To list all packages, use pacman -Q
(scripting that, to list all ".so" files which are installed, by package name would be an interesting exercise).
ls /lib /usr/lib /usr/local/lib

error while loading shared libraries libpng16

I am trying to compile and run this code under ubuntu 14.04. I downloaded and installed libpng version 1.6.12. I am able to compile the code using gcc test.c -lpng but when I try to run it, I get this error:
./a.out: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory
edit:
So I found libpng16.so.16, it was in /usr/local/lib and I copied it to /usr/local/include/libpng16/ and as well to /usr/local/include/ and recompiled the code, anyway the problem still persists.
Any suggestions ?
Ok so I found the solution here. The trick is to run sudo ldconfig after you install some shared library.
You can download the library from the link
https://sourceforge.net/projects/libpng/?source=directory
It will download a file something like "libpng-1.6.32.tar.xz"
Simply extract the file go inside folder and run these commands to install
./configure
make check
make install
Then you need to run after installing any library
ldconfig
I had same problem before I had installed it form below link and problem fixed.
I hope yours would be fixed as well
PNG reference library: libpng

mongo c libs not found on Mac with Eclipse

I built MongoDB C drivers from a tar distro on OSX (Mavericks). Built ok and installed to /usr/local/lib along with libbson. Made links to /usr/lib.
It built libbson-1.0.0.dylib, libbson-1.0.la, libmongoc-1.0.0.dylib, and libmongoc-1.0.la.
Not "*.a" files built tho, for whatever reason, by the makefile.
I added /usr/local/lib to my Eclipse project's lib dir params, and includes to /usr/local/include.
The includes were found during compile but linking failed because symbols from the libbson & libmongoc were not found. I'm winding about the lack of "*.a" files--not sure if Eclipse knows what to do with dylib files.
How can I make Eclipse find the needed libs?
Have you tried to add "-llibbson-1.0.0 -llibbson-1.0 -llibmongoc-1.0" to the linker flags ?

Resources