I've built nginx on my target machine (Linux) with a 3rd party module (ngx_mongo).
This module required two additional libraries to be present: pcre and yajl.
I built and installed these two separately and they installed to /usr/local/lib and headers to /usr/local/include.
I then configured nginx's build: configure --add-module=/home/greg.zoller/working/ngx_mongo
This found all the needed libs and successfully built w/o errors.
Installed nginx to default /usr/local/nginx.
When I go to run /usr/local/nginx/sbin/nginx I get this error:
./nginx: error while loading shared libraries: libyajl.so.2: cannot open shared object file: No such file or directory
Why can't it find libyajl.so.2? This file exists in /usr/local/lib and the build found it.
I ran ldconfig -v and the yajl library was not there. I tried running (as root and not) just ldconfig. No change.
What am I missing?
The dynamic loader only looks for libs present in folders declared in /etc/ld.so.conf. /usr/local/lib may not be there by default. Also when a new lib is added, you need to run ldconfig since the contents of lib folders are cached.
Related
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
I created a custom module for Apache2.4 that uses an external library (MagickWand). I installed it using sudo apt-get install libmagickwand-dev, but now, what I have to do in order to use it with Apache2.4? When I restart the apache2 service I got the undefined symbol error about a function on MagickWand.
I read that I should load the shared object of the library, but how can I create it? Using apxs? Where?
Thank you very much in advance!
there are two config files in apache2 that you will need to modify:
(for linux)
in the /etc/apache2 there are sub directories of interest:
./mods-available and ./mods-enabled and ./conf-available and ./conf-enabled
The ./mods-available directory contains ALL the loadable modules, all with the .load extension on their file name
The ./mods-enabled directory contains links to the loadable modules in the ./mods-available directory that are to be loaded and links to the .conf file for each of the .conf files (for the individual loadable modules) that are actually to be loaded.
the ./conf-available directory contains all the .conf files for the loadable modules
The ./conf-enabled directory contains links to the files in the ./conf-available directory for the loadable modules configurations that will be actually used
Then in the /etc/apache2 directory is the file apache2.conf that can contain (amongst other things) these two statements:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf
This is what directs apache2 to actually load modules and their related conf files
The following response is to help others:
In order to compile a custom apache module using apxs with MagickWand library, first include the header file wand/magick-wand.h in your C file. Let's say it is mod_example.c:
So, in mod_example.c add:
#include "wand/magick-wand.h"
Now, when compiling the module using apxs include the directories which MagickWand will require during the build process using -I flag and mention the library name using -l flag
sudo apxs -c -i -I/usr/include/ImageMagick-6 -I/usr/include/x86_64-linux-gnu/ImageMagick-6 -lMagickWand-6.Q16 /path/to/mod_example.c
Please note, your library version may be different.
After I followed the instructions in (Building Custom ModSecurity Modules)section in modsecurity dev guide in order to compile (mod_tfn_reverse.c) using the command apxs -ca mod_tfn_reverse.c, I'm still finding "fatal errors" such as unable to find the file modsecurity.h mentioned in the header of the C document.
Here is the link to the source on github modsec
Instructions I did:
I am using Ubuntu 14.4 64bits (New installation with updates).
I installed "apache dev" package, to run "APXS" command on terminal.
Downloaded "modsecurity" zip file from github.
I extracted the zip file, then I located where the mod_tfn_reverse.c is.
It's path : ModSecurity/ext/mod_tfn_reverse.c
Then I changed the directory to the targeted file CD modsecurity/ext
as I placed the folder in "home".
Finally, I executed the command apxs -ca mod_tfn_reverse.c.
These are the instructions I did, apxs works, but the compilation fails because "modsecurity.h" declared in the header was not found, I searched this file I found it in another directory (ModSecurity/apache2/modsecurity.h).
So, the difficulty is, how can I successfully compile that specific file and have the module done and ready to use in apache2 server.
I am also confused about what are the other archives, headers, and development tools required to:
to compile a custom apache module.
to compile mod_tfn_reverse.c, in my case, knowing that this is only the starting point to create custom module for modsecurity.
This is covered by the included README:
apxs -I<MODSECURITY_SOURCE_CODE> -I/usr/include/libxml2 \
-ca mod_tfn_reverse.c
I am building locally a dependencies and installing in a local directory. Now I would like to tell CMake to look into that local directory for include and libraries, in addition to all the standard places.
I tried this:
cmake -D CMAKE_LIBRARY_PATH=`realpath ../target`/lib CMAKE_INCLUDE_PATH=`realpath ../target`/include .
But it did not work. Any idea?
You can use the
find_library()
command to search for libraries.
With
include_directories()
you tell cmake where to look for include files
You can first add the folder to your PC's system environment, e.g. called PersonalLib_DIR that points to the folder. Then you can add it for include and libraries by accessing $ENV{PersonalLib_DIR} via CMake:
For include:
include_directories($ENV{PersonalLib_DIR})
For libraries (assume you want to link the aLib.lib under the folder):
target_link_libraries(youProject $ENV{PersonalLib_DIR}/aLib)
I've done this before a couple of times, but somehow I'm stuck this time. I have an executable "myapp" and a own shared library "mylib". In my cmakelists I have the following:
ADD_LIBRARY(mylib SHARED ${SOURCES_LIB})
INSTALL(TARGETS mylib DESTINATION .)
ADD_EXECUTABLE(myapp ${SOURCES_APP})
TARGET_LINK_LIBRARIES(myapp ${QT_LIBRARIES} mylib)
INSTALL(TARGETS myapp DESTINATION .)
Everything compiles and links correctly, but when I start myapp, I get the following error:
error while loading shared libraries: libmylib.so: cannot open shared object file: No such file or directory
The lib and the executable are present in the install directory. When I make my library static by changing the first line of the above cmakelists to:
ADD_LIBRARY(mylib STATIC ${SOURCES_LIB})
then everything works 100%.
Does anyone know what I'm doing wrong?
During the installation of your library and executable, the runtime paths to find the library are stripped from the executable. Therefore your library has to reside in the runtime library search path. For example under Linux, try to set LD_LIBRARY_PATH to the directory that contains the installed library when starting your executable.
This is a very common question about "make install". Actually, there are 3 ways to link a library to your executable file. First, you may use -l -L flags in simple cases. As Benjamin said you may use LD_LIRARY_PATH and write something like: export LD_LIBRARY_PATH=/usr/local/my_lib. In fact this is not a good way. It's much better to use RPATH. There is a very useful doc page about it. Check it out. Well if you write something like this in your top level CMakeLists.txt, it will solve the problem:
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib64")
Add the path of the directory containing the library to the LD_LIBRARY_PATH environment variable, by appanding a new path:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/the/library/
You can check the library is correctly found with the 'ldd' tool:
lld ./executable
If the library is not stated as "not found" it is OK and your executable will be executed properly.
Add the 'export' command to your bashrc to properly set the LD_LIBRARY_PATH variable after each system reboot, otherwise you will have to execute again the 'export' command.