linker

Use absolute value of linker command file variable in 'C' code

I have a linker command file that assigns the top address of the stack into a variable _stack = . + 0x80000; I want to use this address in a 'c' program - I want to copy the stack to another location and then update the stack pointer to point to the new location before doing a destructive memory test on the orginal bank of RAM. I'm ...

Embedding DLLs in a compiled executable

You know, I haven't seen a good answer for this anywhere. Is it possible to embed a pre-existing DLL into a compiled C# executable (so that you only have one file to distribute)? If it is possible, how would one go about doing it? Normally, I'm cool with just leaving the DLLs outside and having the setup program handle everything, but t...

How do I create a dynamic library (dylib) with Xcode?

I'm building few command-line utilities in Xcode (plain C, no Cocoa). I want all of them to use my customized version of libpng, and I want to save space by sharing one copy of the library among all executables (I don't mind re-distributing .dylib with them). Do I need to do some magic to get libpng export symbols? Does "Link Binary Wi...

How do I change OutDir variable in Visual C++?

In the linker the binary destination is specified as: $(OutDir)\$(ProjectName).exe I've looked through every setting and I can't see where OutDir is defined. How do I change this? ...

How to link using GCC without -l and without hardcoding path

I have a shared library that I wish to link an executable against using GCC. The shared library has a nonstandard name not of the form libNAME.so, so I can not use the usual -l option. (It happens to also be a Python extension, and so has no 'lib' prefix.) I am able to pass the path to the library file directly to the link command line, ...

gcc linker issue

I am trying to make a library that wraps libpurple (you shouldn't need to know anything about libpurple to help here). Libpurple in turn loads "plugins" which are just .so's accessed via something like dlopen. Those plugins in turn call back to functions in libpurple. I can build my library just fine, but when it calls the appropriate l...

C++ - static variables initialisation order

C++ guarantees that variables in compilation unit (.cpp file) are initialised in order of declaration. For number of compilation units this rule works for each one separately (I mean static variables outside of classes) , but order between them is undefined. Where I can see some explanations about this order for gcc and MSVC (I know tha...

Having trouble linking a static library C++

I've figured out how to set VC++ to compile code into a .lib file instead of a .exe, but I'm having trouble getting a lib to link together with my other .obj files. Here is how I have the library and application folders set up. (I'm not sure if this is right) AppFolder App.sln App.ncb *.h *.cpp Debug *.obj App.exe ...

C++ template instantiation of function template parameters

Hi, I have the following problem using template instantiation [*]. file foo.h class Foo { public: template <typename F> void func(F f) private: int member_; }; file foo.cc template <typename F> Foo::func(F f) { f(member_); } file caller.cc Foo::func(boost::bind(&Bar::bar_func, bar_instance, _1)); While this c...

How can I specify that library X must be linked statically ?

I have a piece of software which is linked against several libraries. They all exists in a dynamic (.so) and a static (.a) version. By default, when using g++ it chooses the dynamic version of the libraries and that's fine with me. However, one of them absolutely needs to be linked statically. I thought about using -static but then it ...

How to get RPATH with $ORIGIN to work on Code::Blocks GCC?

I'm trying to link an RPATH containing the special string $ORIGIN into an executable built using GCC with the Code::Blocks IDE. I've specified -Wl,-R$ORIGIN in the linker options for the project, but the command line output to GCC is wrong (stripped for clarity): g++ -Wl,-R What is the correct way to specify this argument for Code:...

Multiple definitions of a function template

Suppose a header file defines a function template. Now suppose two implementation files #include this header, and each of them has a call to the function template. In both implementation files the function template is instantiated with the same type. // header.hh template <typename T> void f(const T& o) { // ... } // impl1.cc #in...

Static or dynamic linking the CRT, MFC, ATL, etc.

Back in the 90s when I first started out with MFC I used to dynamically link my apps and shipped the relevant MFC DLLs. This caused me a few issues (DLL hell!) and I switched to statically linking instead - not just for MFC, but for the CRT and ATL. Other than larger EXE files, statically linking has never caused me any problems at all...

Linker Errors C++ Visual Studio 2005

I'm getting a whole bunch of linker errors in Visual studios for methods I'm not even calling directly. I'm a java developer by day, but I have a project I need to do in C++, intended to run on windows machines. Hence, I'm stuck messing about with Visual Studio. Bascally, I have an os project that I added an accessor method to. I compil...

How do I control which symbols a Windows DLL imports from the application?

I'm trying to build a shared library (DLL) on Windows, using MSVC 6 (retro!) and I have a peculiar link issue I need to resolve. My shared library must access some global state, controlled by the loading application. Broadly, what I have is this: application.c: static int g_private_value; int use_private_value() { /* do somethin...

VC++ linker errors on std::exception::_Raise and std::exception::exception

I am using Visual C++ 2005 Express Edition and get the following linker errors: 19>mylib1.lib(mylibsource1.obj) : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall std::exception::_Raise(void)const " (__imp_?_Raise@exception@std@@QBEXXZ) referenced in function "protected: static void __cdecl std::v...

Multiple definitions due to multiple includes of same header file

Hello, I have a header file x.h which is included by more than one *.c source files. This header file has some structure variables defined. I have put multiple inclusion prevention guard at the beginning of the header file as: #ifndef X_H #define X_H ... .. //header file declarations and definitons. #endif//X_H On building I get l...

C++ : how to link against libA.so and not libA-X.Y.Z.so

I have a library A, that I develop. When I deploy it on a machine, the corresponding libA.so and libA-X.Y.Z.so are put in /usr/lib (X.Y.Z being the version number). Now I develop a library B, which uses A. When I link B, I use the flag -lA. Then "ldd libB.so" gives me : (...) libA-X.Y.Z.so => /usr/lib/libA-X.Y.Z.so (...) My problem...

LNK2001 error when compiling apps referencing STLport-5.1.4 with VC++ 2008

I apologize in advance for the long post... I used to be able to build our VC++ solutions (we're on VS 2008) when we listed the STLPort include and library directories under VS Menu > Tools > Options > VC++ Directories > Directories for Include and Library files. However, we wanted to transition to a build process that totally relies o...

iostream linker error

I have some old C code that I would like to combine with some C++ code. The C code used to have has the following includes: #include <windows.h> #include <stdio.h> #include <string.h> #include "mysql.h" Now I'm trying to make it use C++ with iostream like this: #include <windows.h> #include <stdio.h> #include <string> #include <iost...