shared-libraries

Shared library on Linux and -fPIC error

本秂侑毒 提交于 2019-11-29 10:33:08
I am trying to compile a shared library in Linux using a Makefile created with Cmake, but running make I obtain the following error: Linking CXX shared library libcpp-lib.so /usr/bin/ld: /home/davide/Desktop/boost_1_55_0/stage/lib/libboost_system.a(error_code.o): relocation R_X86_64_32 against .rodata.str1.1 can not be used when making a shared object; recompile with -fPIC /home/davide/Desktop/boost_1_55_0/stage/lib/libboost_system.a: could not read symbols: Bad value collect2: ld returned 1 exit status make[2]: *** [libcpp-lib.so] Error 1 make[1]: *** [CMakeFiles/cpp-lib.dir/all] Error 2 make

Is there anything like Python's ctype for PHP? Accessing libraries without the need to write an extension?

谁都会走 提交于 2019-11-29 10:23:55
Python has ctypes to access libraries. In PHP you write extensions for everything. Popular extensions like the one for libgd are available almost everywhere. Is there any extension which works like Python's ctypes, letting you access libraries without the need to write an PHP extension? You're looking for ffi . There is a PHP extension (irony?) called ffi . FFI stands for Foreign Function Interface , which is the generic term for when a language calls libraries written in another language. PHP 7.3 will have FFI (Foreign Function Interface). I don't think there is such a thing : in PHP, the

How to build and install gcc with built-in rpath?

烈酒焚心 提交于 2019-11-29 09:54:06
I'm trying to build and install my own gcc 4.7.2 in /usr/local to use in place of the gcc 4.4.6 in /usr. (This is on CentOS 6.3.) gcc makes executables and dynamic libraries that dynamically link to its own dynamic libraries, e.g. libstdc++.so. How do I build and install gcc so that the generated binaries automatically get a linker -rpath option (-rpath /usr/local/lib64) that causes dynamic libraries in /usr/local/lib64 to be linked instead of those in /usr/lib64 or /lib64? If it works properly, after I build an executable with the gcc without specifying "-Wl,-rpath=/usr/local/lib64", when I

How to use useDynLib() correctly in an R package namespace file

蓝咒 提交于 2019-11-29 08:55:29
问题 Although a few solutions exist on the internet, I found none of those suitable for the problem I'm curerntly facing (though maybe I'm simply too dumb): I'm trying to build an R package which makes extensive use of a shared object compiled by a Makefile (yes, bad practice, I know, but a Makevars file just can't be told to compile C and Fortran code into one shared object) from code in the package's src directory. No matter where I compile that .so to (I tried the src , libs and package base

how to pass argument to constructor on library load?

柔情痞子 提交于 2019-11-29 08:51:22
I am trying to create a shared library in Linux. How can I pass an argument to function my_load() when library is loaded? In my C application, I make a call to test_func() then it automatically executes my_load() first before the called function then lastly it executes my_unload() #include <stdio.h> void __attribute__ ((constructor)) my_load(int argc, char *argv[]); void __attribute__ ((destructor)) my_unload(void); void test_func(void); void my_load(int argc, char *argv[]) { printf("my_load: %d\n", argc); } void my_unload(void) { printf("my_unload\n"); } void test_func(void) { printf("test

makefile for creating (.so) file from existing files

眉间皱痕 提交于 2019-11-29 08:42:29
I have 4 files: 1.c , 1.h , 2.c , 2.h . I need a makefile, which will create a dynamic library (.so) from those 4 files. I have tried to write a makefile like this: library.so : 1.c 1.h 2.c 2.h but it did not work. It would be great, if someone helps me, thanks. Basile Starynkevitch Something like CC=gcc CFLAGS= -Wall -g -O -fPIC RM= rm -f .PHONY: all clean all: library.so clean: $(RM) *.o *.so library.so: 1.o 2.o $(LINK.c) -shared $< -o $@ 1.o: 1.c 1.h 2.h 2.o: 2.c 1.h 2.h But this is untested! I am assuming Linux with GNU make , and a directory containing only the source code of your library

Shared object in Linux without symbol interposition, -fno-semantic-interposition error

喜夏-厌秋 提交于 2019-11-29 07:58:25
Shared objects (*.so) in Unix-like systems are inefficient because of the symbol interposition: Every access to a global variable inside the .so needs a GOT lookup, and every call from one function to another inside the .so needs a PLT lookup. I was therefore happy to see that gcc version 5.1 has added the option -fno-semantic-interposition. However, when I try to make a .so where one function calls another without using a PLT, I get the error message: relocation R_X86_64_PC32 against symbol `functionname' can not be used when making a shared object; recompile with -fPIC I expected the option

Mixing static libraries and shared libraries

不羁岁月 提交于 2019-11-29 07:22:21
I have a project where I have one static library libhelper.a and another with my actual shared object library, libtestlib.so . My goal is to link libhelper.a into libtestlib.so . Is that possible on Linux/BSD? When I tried and created a test program I got the following errors: ./prog1:/usr/local/lib/libtestlib.so.1.0: undefined symbol '' My guess is that this is occurring because libhelper.a was not compiled with -fPIC while libtestlib.so was. What is the proper way to build programs that use shared libraries that also have dependancies on static libraries? Thanks! My goal is to link libhelper

dlopen - Undefined symbol error

空扰寡人 提交于 2019-11-29 07:07:16
I'm using dlopen to load a shared library at run time dlopen("SharedLibarary1.so", RTLD_NOW | RTLD_GLOBAL); In that shared object I refer to a const char* defined in another shared library "SharedLibarary2.so". The Executable, and both the libraries are built using -rdynamic. But I still get the run time error when using dlopen: "/usr/lib/SharedLibarary1.so: undefined symbol" and points to the mangled const char* has the undefined symbol. Whith GDB "info share" I can see that the second library is not loaded at the point of the error. How ever that problem goes away if I do a dlopen on the

How does adding a private member variable break C++ ABI compatibility?

时光怂恿深爱的人放手 提交于 2019-11-29 07:03:26
问题 The pimpl idiom is commonly used in order to allow changing code in dynamically linked libraries without breaking ABI compatibility and having to recompile all the code that depends on the library. Most of the explanations I see mention that adding a new private member variable changes the offsets of public and private members in the class. That makes sense to me. What I don't understand is how in practice this actually breaks the dependent libraries. I've done a lot of reading on ELF files