static-linking

How Linkers Resolve Multiply Defined Global Symbols in C

夙愿已清 提交于 2019-12-24 03:37:54
问题 My Textbook says that: "Functions and initialized global variables get strong symbols. Uninitialized global variables get weak symbols.Given a strong symbol and multiple weak symbols, choose the strong symbol" So I create two files to see: file1.c: int number; int main(int argc, char *argv[]) { printf("%d",number); return 0; } file2.c (just one line): int number = 2018; and I ran gcc -Wall -o program file1.c file2.c and the output is 0, which I can understand before I study linker ('number'

C++ Undefined symbol related to std::string in static lib

独自空忆成欢 提交于 2019-12-23 22:43:35
问题 I am building a shared lib by linking a bunch of code with a static lib (.a) on Linux in C++. I have a method defined in a static library. When I use nm -C to print the symbol in that static library is appears as: Alembic::AbcCoreFactory::v9::IFactory::getArchive(std::string const&, Alembic::AbcCoreFactory::v9::IFactory::CoreType&) The symbol is not defined in the output .so file (the library I am building), but when I list the undefined symbols using nm -uC it prints: Alembic::AbcCoreFactory

gcc / ld: overlapping sections (.tbss, .init_array) in statically-linked ELF binary

大城市里の小女人 提交于 2019-12-23 14:59:28
问题 I'm compiling a very simple hello-world one-liner statically on Debian 7 system on x86_64 machine with gcc version 4.8.2 (Debian 4.8.2-21): gcc test.c -static -o test and I get an executable ELF file that includes the following sections: [17] .tdata PROGBITS 00000000006b4000 000b4000 0000000000000020 0000000000000000 WAT 0 0 8 [18] .tbss NOBITS 00000000006b4020 000b4020 0000000000000030 0000000000000000 WAT 0 0 8 [19] .init_array INIT_ARRAY 00000000006b4020 000b4020 0000000000000010

ImageMagick static compilation with another project gives linker errors

China☆狼群 提交于 2019-12-23 11:48:15
问题 I've downloaded the ImageMagick source, compiled the wizard to create a Visual Studio solution for static linkage, and included the static library Magick++ project in my sample project (code below). I've also added a dependency on that project and included the .lib file in the solution, nothing helps. #include <Magick++.h> int main() { Magick::Image image; bool test = image.isValid(); return 0; } This gives several linker errors, such as: unresolved external symbol "__declspec(dllimport)

Libtorch/Pytorch Dilemma when combined static library into one STATIC library

六月ゝ 毕业季﹏ 提交于 2019-12-23 05:16:01
问题 I have around 26 static libraries such as liba.a, libb.a, libc.a, ..., libz.a . There are two catches here: 1) circular dependencies between for example liba.a and libb.a ; 2) some lib*.a has static global registration code which is unreferenced, but shall NOT be stripped away. Thanks to stackoverflow, I managed to solve above two problems with the ld option -Wl,--whole-archive -la -lb -lc -ld -le ...(omitted)... -lz -Wl,--no-whole-archive -lpthread -lm -ldl -lrt -fopenmp , and the executable

configure.in: AM_DISABLE_SHARED doesn't change my Makefile

别来无恙 提交于 2019-12-23 01:10:50
问题 I'm extremely new to using Makefiles and autoconf. I'm using the Camellia image library and trying to statically link my code against their libraries. When I run "make" on the Camellia image library, I get libCamellia.a, .so, .la, and .so.0.0.0 files inside my /usr/local/lib directory. This is the command I use to compile my code with their libraries: gcc -L/usr/local/lib -lCamellia -o myprogram myprogram.c This works fine, but when I try to statically link, this is what I get: gcc -static -L

gcc: confused about -static -shared -fPIE -fPIC -Wl,-pie

痴心易碎 提交于 2019-12-22 18:38:13
问题 I'm trying to build clang, with all library static linked in. So that I can run it on CentOS 6 with ancient GCC 4.4 version. At first, I think adding the option -static by turning on LLVM_BUILD_STATIC is enough. But in the link stage, it errors out. dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/../lib64/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie So, I add -fPIE -Wl,-pie to CMAKE_CXX_FLAGS, and it says --

gcc: confused about -static -shared -fPIE -fPIC -Wl,-pie

此生再无相见时 提交于 2019-12-22 18:38:02
问题 I'm trying to build clang, with all library static linked in. So that I can run it on CentOS 6 with ancient GCC 4.4 version. At first, I think adding the option -static by turning on LLVM_BUILD_STATIC is enough. But in the link stage, it errors out. dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/usr/lib/../lib64/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie So, I add -fPIE -Wl,-pie to CMAKE_CXX_FLAGS, and it says --

Compiling mono as static library

我的未来我决定 提交于 2019-12-22 17:46:20
问题 I want to compile libmono as static library at Windows. Target platform is Windows x86. Build environment: Windows 7 64-bit, VC++ Express 2010 What i have already done. 1) Downloaded mono 2.10.8 sources. 2) Opened mono.sln from msvc folder and ensured that everything is compilling. 3) Then i've made some changes: 3.1) General->Project Defaults->Configuration Type: Static library (.lib) 3.2) General->Project Defaults->Use of MFC: Use Standard Windows Libraries 3.3) C/C++->Code Generation-

How to debug linker errors? Getting undefined reference errors when statically linking ICU

纵然是瞬间 提交于 2019-12-22 10:46:58
问题 I've built the static libraries for ICU 49 and 50 but when linking with either one of them I still get 667 linker errors like the ones below. How can I approach debugging this and figuring out what the problem is? The ICU support list has offered no help at all. clang++ -ccc-gcc-name g++ -Wl,-E -o velocity main.o city.o auto_lua.o obj_builder.o index.o obj.o str.o db.o datetime.o msg_parser.o task_scheduler.o gc.o global_settings.o transaction.o schema.o skip_node.o util.o thread_context.o