static-linking

How to use pkg-config to link a library statically

六眼飞鱼酱① 提交于 2019-11-30 20:13:59
I'd like to link libpng found by pkg-config statically. pkg-config --libs --static libpng outputs -L/usr/local/Cellar/libpng/1.6.15/lib -lpng16 -lz I have both libpng16.a libpng16.dylib in that directory, and if I use these flags the library gets linked dynamically. How can I tell either pkg-config or the linker (preferably in some portable-ish way) that I really want it linked statically? I've tried adding -static before pkg-config's flags, but that makes clang's ld try and fail to link "crt0.o". The pkg-config --static option relies on proper tagging in the .pc files . If providing the -

Why is my static library so huge?

笑着哭i 提交于 2019-11-30 19:37:26
I have a C++ compiled static library of about 15 classes and their member functions and stuff, and compiled, it's almost 14 megabytes. It links to Google's dense hash table library and MPIR, which is like GMP for Windows, but I did that in a plain exe and it was a few kilobytes. Why is it so massive? What can I do to reduce its size? It seems like there's other programs which are far more complicated than mine that are far smaller. Compiled with Visual C++, command line is: /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy

Android Static Linking vs Dynamic Linking against glibc

与世无争的帅哥 提交于 2019-11-30 19:20:11
I have been cross-compiling some Linux tools (and some of my own C code) to Android and one of the challenges that I face is that Android's libc has some missing/stripped components and I end up patching my code to make it work with Android's libc (for e.g. a problem like this http://credentiality2.blogspot.com/2010/08/compile-ncurses-for-android.html ) Q1 : How do I go about statically linking against glibc (and other dependencies) while cross-compiling with the arm toolchain (or ndk-build)? Q2 : Is it a good idea to statically link against glibc for binaries for Android? Should I expect

Qt 5.4 static build produces “unresolved external symbol” link error in Visual Studio 2013

匆匆过客 提交于 2019-11-30 17:44:38
问题 I want to use a static build of Qt 5.4. Since there is no precompiled static build available, you have to build one from the Qt source code yourself. My environment is the following: Windows 7 x64 Visual Studio 2013 Ultimate Update 4 Qt5 Visual Studio Add-in 1.2.4 ActivePerl / ActivePython installed (required to build Qt source) My procedure was the following (cf. Qt Documentation > Qt 5.4 > Qt for Windows - Building from Source): Download qt-everywhere-opensource-src-5.4.0.zip Extract to a

C++ linking problems, seems like I can't link against standard C++ stuff

亡梦爱人 提交于 2019-11-30 17:09:17
I am trying to use a library I've compiled myself in an iOS app. The library is the Tesseract OCR lib. It seems like compiling that (and its dependencies) have gone ok. However, when I try to link against this lib in my app project, the app fails to link. The link errors surprise me; it seems like there are problems with the Tesseract stuff finding pretty standard C++ stuff. Any suggestions about what I might be doing wrong would be most helpful. Here is a snippet of the kind of link errors I'm seeing. Undefined symbols for architecture armv7: "std::string::find_last_of(char const*, unsigned

Self-contained shared library

孤者浪人 提交于 2019-11-30 14:20:12
I need to create a shared library whose own dependencies including libc/libstdc++ have to be statically linked to it to produce a self-contained binary. I tried to do this g++ -c -fpic -o foo.o foo.cpp g++ -static -shared -o foo.so foo.o which fails with: /usr/bin/ld.bfd.real: /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/crtbeginT.o: relocation R_X86_64_32 against `__TMC_END__' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/crtbeginT.o: could not read symbols: Bad value collect2: error: ld returned 1 exit status Can

Can I link MSVCRT statically with mingw?

帅比萌擦擦* 提交于 2019-11-30 14:08:15
I have C program I compile with mingw on Windows. It works fine but requires MSVCRT.DLL . I want to link that statically (like I can do in Visual Studio). Is this possible? I tried -static flag to gcc and it didn't make any change. What about C++ program using also standard C++ library? I believe that MinGW doesn't use the static runtime library for copyright reasons. You can maybe try to use newlib ( http://sourceware.org/newlib/ ) to create an executable that doesn't link to msvcrt.dll Having spent a while searching for this myself, I came across this post introducing the in-progress Mingw32

Cannot compile a simple Qt program in MT mode as opposed to MD in Visual Studio 2010

拜拜、爱过 提交于 2019-11-30 13:17:12
问题 I'm trying to compile using MTd in Visual Studio 2010 instead of MDd (so that the dll's are packaged in and i won't need to distribute them with my exe), but I keep getting "fatal error LNK1169: one or more multiply defined symbols found" during compilation. MDd compiles fine but does not work without MSVCP100.dll on other computers. I'm using a static build of Qt and I'm trying to build the default Qt program that comes with the VS add-in. Is there another way to force the linker to compile

C-library not linking using gcc/g++

[亡魂溺海] 提交于 2019-11-30 12:35:13
问题 I have a c-library which I use in gcc. The library has the extension .lib but is always linked as a static library. If i write a program which uses the library as c-code, everything as a-ok. If I however rename the file to .cpp (doing simple stuff that works in both c/c++) I get undefined reference. These are simple small programs I write for testing purposes so no fancy stuff. I compile using: gcc -g -Wall -I <path to custom headers> -o program main.c customlibrary.lib -lm -lpthread The

How to use static linking with OpenSSL in C/C++

只愿长相守 提交于 2019-11-30 11:56:32
I wrote simple apps with Openssl in C and C++. I compile them like this: gcc openssltest.c -o openssltest -lcrypto g++ openssltest.cpp -o openssltest -lcrypto And its all ok but only, when you have Openssl installed. I would like to compile it that I can run them on OS where theres no Openssl installend (linux-like OS). I tried this: gcc -c openssltest.c -lcrypto -static gcc openssltest.o -o openssltest -lcrypto -static and same for C++: g++ -c openssltest.cpp -lcrypto -static g++ openssltest.o -o openssltest -lcrypto -static But have those errors: /usr/lib/gcc/x86_64-linux-gnu/4.7/../../..