shared-libraries

Telling ld where to look for directories via an environment variable

痴心易碎 提交于 2021-02-06 10:52:06
问题 I'm grading C and C++ files for a class, and this assignment uses the GSL library. Since I don't have root permission on my computer, my GSL library is installed in my home directory, and thus I need to tell compilers and linkers where to find it. This isn't a problem when I write a program myself, because I just add the appropriate -L and -I flags to gcc. But when I'm compiling student's files, I don't want to edit every one of their makefiles. Instead, I want to put the appropriate

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

落花浮王杯 提交于 2021-02-06 10:17:56
问题 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

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

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

Is it safe to call dlclose(NULL)?

怎甘沉沦 提交于 2021-02-05 02:52:52
问题 I experience a crash when I pass a null pointer to dlclose . Should I check for null before calling dlclose ? POSIX tells nothing about this: http://pubs.opengroup.org/onlinepubs/7908799/xsh/dlclose.html Is it undefined behaviour or a bug in dlclose implementation? 回答1: This is tricky. POSIX states that if handle does not refer to an open object, dlclose() returns a non-zero value from which you could infer that it should detect, for an arbitrary pointer, whether that pointer refers to an

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

Create shared library with undefined reference using gcc, Unix/Windows differences

扶醉桌前 提交于 2021-01-29 21:13:25
问题 I want to build a simple library with some undefined reference, as you can see in function_two.c , I call three() which is not defined. header.h void one(); void two(); void three(); function_one.c #include <stdio.h> #include "header.h" void one() { printf("one\n"); } function_two.c #include <stdio.h> #include "header.h" void two() { printf("two\n"); three(); } Using Linux , I compile both files and then I link them linux:~/example$ gcc -c -Wall -Werror -fpic function_one.c linux:~/example$