linker

Creating a shared library from a static library using GNU toolchain (gcc/ld)

走远了吗. 提交于 2021-02-06 10:15:06
问题 I am having trouble generating a shared object from a static library. While I know there are other alternatives, I am now bothered (as opposed to stuck) by why this isn't working and how to make it work. Below is very simple source code I am using. get_zero.c #include "get_zero.h" int get_zero(void) { return 0; } get_zero.h int get_zero(void); main.c #include <stdio.h> #include <string.h> #include "get_zero.h" int main(void) { return get_zero(); } The goal is create two functionally equal

ELF, PIE ASLR and everything in between, specifically within Linux

帅比萌擦擦* 提交于 2021-02-06 02:59:27
问题 Before asking my question, I would like to cover some few technical details I want to make sure I've got correct: A Position Independent Executable (PIE) is a program that would be able to execute regardless of which memory address it is loaded into, right? ASLR (Address Space Layout Randomization) pretty much states that in order to keep addresses static, we would randomize them in some manner, I've read that specifically within Linux and Unix based systems, implementing ASLR is possible

Linking a shared library using gcc

匆匆过客 提交于 2021-02-05 20:43:38
问题 I have a shared library (*.so) created using Real View Compiler Tools (RVCT 3.2) on windows target. Then I try to link this *.so file with my application using gcc on linux system. What is the gcc option to link this shared library with my application linux? My question is, is the -shared option, which is used as gcc -shared myfile.so ..., used to create the SO file or to link the SO file? I believe it creates something like: gcc -lmyfile.so Is this enough? Or is there any other switch to

Re-export Shared Library Symbols from Other Library (OS X / POSIX)

会有一股神秘感。 提交于 2021-02-05 20:33:13
问题 My question is fairly OS X on x86-64 specific but a universal solution that works on other POSIX OSes is even more appreciated. Given a list of symbol names of some shared library (called original library in the following) and I want my shared library to re-export these symbols. Re-export as in if someone tries to resolve the symbol against my library I either provide my version of this symbol or (if my library doesn't have this symbol) forward to the original library's symbol. I don't know

Re-export Shared Library Symbols from Other Library (OS X / POSIX)

人走茶凉 提交于 2021-02-05 20:32:15
问题 My question is fairly OS X on x86-64 specific but a universal solution that works on other POSIX OSes is even more appreciated. Given a list of symbol names of some shared library (called original library in the following) and I want my shared library to re-export these symbols. Re-export as in if someone tries to resolve the symbol against my library I either provide my version of this symbol or (if my library doesn't have this symbol) forward to the original library's symbol. I don't know

gcc: Reduce libc required version

非 Y 不嫁゛ 提交于 2021-02-05 20:01:53
问题 I am trying to run a newly compiled binary on some oldish 32bits RedHat distribution. The binary is compiled C (not++) on a CentOS 32bits VM running libc v2.12. RedHat complains about libc version: error while loading shared libraries: requires glibc 2.5 or later dynamic linker Since my program is rather simplistic, It is most likely not using anything new from libc. Is there a way to reduce libc version requirement 回答1: An untested possible solution What is "error while loading shared

Run-time linking to dynamic libraries not on LD_LIBRARY_PATH

只愿长相守 提交于 2021-02-04 16:32:40
问题 I'm trying to link a project of mine to a particular set of custom-compiled libraries placed on the project's base directory [proj_dir]/lib - not on any of the system's /lib, /usr/lib or /usr/local/lib - to avoid conficts with the installed stock versions of those same libraries. I'm able to compile the project by passing the library path with the -L flag, but I get error while loading shared libraries libXXX.so: cannot open shared object file: No such file or directory when I run the

Run-time linking to dynamic libraries not on LD_LIBRARY_PATH

萝らか妹 提交于 2021-02-04 16:32:29
问题 I'm trying to link a project of mine to a particular set of custom-compiled libraries placed on the project's base directory [proj_dir]/lib - not on any of the system's /lib, /usr/lib or /usr/local/lib - to avoid conficts with the installed stock versions of those same libraries. I'm able to compile the project by passing the library path with the -L flag, but I get error while loading shared libraries libXXX.so: cannot open shared object file: No such file or directory when I run the

Multiple definition of first defined here gcc

寵の児 提交于 2021-02-04 14:29:50
问题 I have these files consumer.cpp consumer.hpp defines.hpp main.cpp makefile producer.cpp producer.hpp here's the file defines.hpp #ifndef DEFINES_HPP #define DEFINES_HPP #include <cassert> #include <pthread.h> #include <queue> #include <stdlib.h> #include <string> #include <unistd.h> pthread_mutex_t set_queue_mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t condition_var = PTHREAD_COND_INITIALIZER; std::queue<int> q; #endif // DEFINES_HPP This defines.hpp file is included in the producer.hpp

Static variable is initialized twice

让人想犯罪 __ 提交于 2021-02-04 13:17:07
问题 Consider I have a static variable in a compilation unit which ends up in a static library libA. I then have another compilation unit accessing this variable which ends up in a shared library libB.so (so libA must be linked into libB). Finally I have a main function also accessing the static variable from A directly and having a dependency to libB (so I link against libA and libB). I then observe, that the static variable is initialized twice, i.e. its constructor is run twice! This doesn't