static-linking

C-library not linking using gcc/g++

时光怂恿深爱的人放手 提交于 2019-11-30 03:04:16
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 above works like a charm. However: g++ -g -Wall -I <path to custom headers> -o program main.cpp

Android Static Linking vs Dynamic Linking against glibc

只谈情不闲聊 提交于 2019-11-30 02:51:01
问题 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)?

Proper way to link a static library using GCC

ⅰ亾dé卋堺 提交于 2019-11-30 00:10:54
Why is it that some static libraries (lib*.a) can be linked in the same way that shared libraries (lib*.so) are linked (ld -l switch), but some can not? I had always been taught that all libraries, static or not, can be linked with -l..., however I've run into one library so far (GLFW), which does nothing but spew "undefined reference" link errors if I attempt to link it this way. According to the response on this question , the "proper" way to link static libraries is to include them directly, along with my own object files, rather than using -l. And, in the case of the GLFW library, this

Why create a .a file from .o for static linking?

痴心易碎 提交于 2019-11-29 23:06:34
Consider this code: one.c: #include <stdio.h> int one() { printf("one!\n"); return 1; } two.c: #include <stdio.h> int two() { printf("two!\n"); return 2; } prog.c #include <stdio.h> int one(); int two(); int main(int argc, char *argv[]) { one(); two(); return 0; } I want to link these programs together. So I do this: gcc -c -o one.o one.c gcc -c -o two.o two.c gcc -o a.out prog.c one.o two.o This works just fine. Or I could create a static library: ar rcs libone.a one.o ar rcs libtwo.a two.o gcc prog.c libone.a libtwo.a gcc -L. prog.c -lone -ltwo So my question is: why would I use the second

Create a static Haskell Linux executable

99封情书 提交于 2019-11-29 21:30:17
It's not often two things I love so much come together to cause me so much annoyance (besides my kids). I've written a Haskell program at work that uses libraries like text, xml-enumerator, attoparsec-text, etc. I have it working properly on my Windows machine at work, my Ubuntu virtual machine at work (32-bit), my Ubuntu desktop (32-bit again) and an EC2 instance running Ubuntu (64-bit). Our client is running CentOS 5.3, 64-bit. I can't for the life of me get this executable to run properly. I tried creating a static executable using: ghc --make myprog.hs -optl-static -optl-pthread But when I

Is there a way to determine which version of Visual Studio was used to compile a static library?

南楼画角 提交于 2019-11-29 20:58:13
I have a collection of static libraries (.lib) files one of which may have been built with a different version of Visual Studio. This is causing the code generation of a project that links against all of them to fail. Is there any way to determine which version of Visual Studio was used to compile a static library? James McNellis For release libraries, it's unlikely that you could determine the version. For debug libraries, you can use dumpbin : dumpbin /rawdata:1 library.lib The assembly manifest should be at the beginning of the dump and will contain the version of the CRT the library

Self-contained shared library

扶醉桌前 提交于 2019-11-29 20:33:43
问题 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

Static methods in C++

大兔子大兔子 提交于 2019-11-29 20:02:27
I am having a little trouble working with static methods in C++ Example .h: class IC_Utility { public: IC_Utility(); ~IC_Utility(); std::string CP_PStringToString( const unsigned char *outString ); void CP_StringToPString( std::string& inString, unsigned char *outString, short inMaxLength ); static void CP_StringToPString( std::string& inString, unsigned char *outString); void CP_StringToPString( FxString& inString, FxUChar *outString); }; Example .cpp: static void IC_Utility::CP_StringToPString(std::string& inString, unsigned char *outString) { short length = inString.length(); if( outString

Why does gcc not implicitly supply the -fPIC flag when compiling static libraries on x86_64

核能气质少年 提交于 2019-11-29 19:05:00
I've had numerous problems compiling shared objects that link statically against static libraries. This problem only shows up on x84_64 platforms. When doing the same compilation work on x86_32 I do not have any problems. Perhaps this is a OS specific GCC configuration thing, but my research indicates that its how GCC works on x86_64 platforms. Anyhow, I am using gcc 4.4.3 on Ubuntu 10.04 x86_64. How is the problem fixed ?... Making sure all the static library dependencies are compiled with -fPIC. Question 1: What is the difference between -fpic and -fPIC (apparently -fPIC generates more

Why doesn't the linker complain of duplicate symbols?

此生再无相见时 提交于 2019-11-29 16:57:09
I have a dummy.hpp #ifndef DUMMY #define DUMMY void dummy(); #endif and a dummy.cpp #include <iostream> void dummy() { std::cerr << "dummy" << std::endl; } and a main.cpp which use dummy() #include "dummy.hpp" int main(){ dummy(); return 0; } Then I compiled dummy.cpp to three libraries, libdummy1.a , libdummy2.a , libdummy.so : g++ -c -fPIC dummy.cpp ar rvs libdummy1.a dummy.o ar rvs libdummy2.a dummy.o g++ -shared -fPIC -o libdummy.so dummy.cpp When I try compile main and link the dummy libs g++ -o main main.cpp -L. -ldummy1 -ldummy2 There is no duplicate symbol error produced by linker. Why