linker

Object code, linking time in C language

When compiling, C produces object code before linking time. I wonder if object code is in the form of binary yet? If so, what happened next in the linking time? ...

LNK2019 when converting an app to use DLLs

(Re-written for clarity) I have a multi-project solution that I am looking to convert from using .lib to .DLL files. I have created my declspec macros and applied it to **every class except for those in the project that creates the final .exe. The linker is throwing a fit on just about everything, however. I have set up to ignore err...

ld cannot find library that is installed

I'm sitting on an OpenSuse 11.1 x64 Box and I have a module that uses sigc++. When linking like this: g++ [a lot of o's, L's and l's] -lsigc-2.0 I get /usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: cannot find -lsigc-2.0 However the library is there. In the filesystem: $ sudo find / -name "libsigc-2.0*"...

'operater new': redefinition, different linkage (using _dllspec on redefined new operator)

I am using __declspec(dllimport/export) on a debug version of new as such: #ifdef _DEBUG DECLSPECCORE extern void* operator new(unsigned int size, const char* file, int line); extern void* operator new[](unsigned int size, const char* file, int line); extern void operator delete(void* address, const char* file, int line); extern v...

Under what conditions will you get unresolved external symbol for __declspec(dllimport)?

I am converting an application to use .dlls and I'm riddled with linker errors stating unersolved external symbol"__declspec(dllimport) public: void __thiscall Rail::SetNextrail(class Rail *)" There is more gibberish at the end of this error message. Why should this happen and how do you fix it? __declspec(dllimport) is be...

How to make gcc or ld report undefined symbols but not fail?

If you compile a shared library with GCC and pass the "-z defs" flag (which I think just gets passed blindly on to ld) then you get a nice report of what symbols are not defined, and ld fails (no .so file is created). On the other hand, if you don't specify "-z defs" or explicitly specify "-z nodefs" (the default), then a .so will be pro...

Warning linking boost lib in WDK build ("LNK4217: locally defined symbol _ imported in function _")

I'm building the below example boost-consuming user-mode app with the WDK, but I'm getting the following errors when linking with the boost libraries that I built earlier using bootstrap and .\bjam, from the same terminal window. IIUC, MSDN says it's because the (hideously mangled) function - which appears to be a C++ std lib function -...

LNK4075: ignoring '/EDITANDCONTINUE' due to '/OPT:ICF' specification

I recently converted a multi-project solution to use .dlls instead of .libs for each of the projects. However, I now get a compiler warning for each project as stated in the example. MSDN didn't serve to be all that helpful with this. Why is this and howcan I solve it? Warning 2 warning LNK4075: ignoring '/EDITANDCONTINUE' due...

Including header file with global variable

I need to include a header file that contains some global variables (not mine so I cannot change it). How do I do this so that the variables within the included file are considered 'extern' in all but one case? ...

Exporting template code = dangerous? (MSVC)

As I noted in another SO question, I came across this article. The issue came up when I compiled boost 1.40 via MSVC7.1 and several C4251 warnings popped up. Now, after reading said article, I wonder: Is it generally discouraged to export template code, e.g. class DLLEXPORT_MACRO AClass { public: std::vector<int> getVecCopy() { retu...

The procedure entry point could not be located in the dynamic link library Core.dll.

I am converting my project to use DLLs and am trying to break apart my Singleton class to avoid using templates. My class, LudoMemory, originally inherited from Singleton. I am trying to give it the functions to destroy and create itself now and have my main engine not rely on the Singleton. I have written a simple destroy method li...

Why does compiling a shared object with GCC always result in undefined references to main?

I'm running Solaris, so it's possible that this is specific to running GCC on Solaris. If I use GCC to generate a shared object, and then run nm on it to see undefined symbols, there will always be a reference to main: [624] | 0| 0|NOTY |GLOB |0 |UNDEF |main If I manually generate the same shared object using ld,...

Building Visual C++ app that doesn't use CRT functions still references some

This is part of a series of at least two closely related, but distinct questions. I hope I'm doing the right thing by asking them separately. I'm trying to get my Visual C++ 2008 app to work without the C Runtime Library. It's a Win32 GUI app without MFC or other fancy stuff, just plain Windows API. So I set Project Properties -> Confi...

How to link an arm .o file into an Xcode project

I have a gnu built object file I need to include in an Xcode iPhone project. The .o file format is arm, via 'otool -h': Mach header magic cputype cpusubtype caps filetype ncmds sizeofcmds flags 0xfeedface 12 0 0x00 1 3 1316 0x00002000 But Xcode rejects it, complaining that "file is not ...

Linking a shared library against a static library: must the static library be compiled differently than if an application were linking it?

At least on Linux and Solaris, static libraries are really just a bunch of compiled .o's tossed into one big compressed file. When compiling a static library, usually the -fpic flag is ommited, so the generated code is position dependent. Now say my static library is B. I've built it and have the resulting .a file which is really just ...

How do I embed data into a Mac OS X mach-o binary file's TEXT Section?

I have a Mac OS X command-line tool that would benefit from having some data embedded in the binary file itself. I know mach-o files support multiple segments, some of which can be used for storing arbitrary data. But I can't find a command-line tool to do that. While I know there are other, probably simpler ways (e.g. convert the data...

How do I force the linker to include a function I need during debugging?

I often make small methods to assist debugging, which aren't used in the actual program. Typically most of my classes has an AsString-method which I add to the watches. I know Delphi 2010 has visualizers, but I'm still on 2007. Consider this example: program Project1; {$APPTYPE CONSOLE} uses SysUtils; type TMyClass = class F ...

Code Banking with SDCC

I need to use code banking in an 8051 microcontroller to fit all the code. SDCC says it supports it, but I'm having trouble at the linking step. I have a test project with 3 files: main.c, func1.c, and bank.asm. The main function should call func1() and then sit in a while loop. But func1() is in a different code bank. // main.c int...

Objective-C with cpp extensions, I don't know what I'm doing...

So I'm still feeling like a novice at times when strange errors jump out of XCode. Yesterday I started getting this: ___gxx_personality_v0", referenced from: ___gxx_personality_v0$non_lazy_ptr That was when building a unit test target that used a ".mm" file in XCode with the iPhoneSDK. The error went away when I changed the file ...

How to I find the filename of a library via the library name?

How to I find the filename of a library via the library name? In otherwords, when I use "-lc", I know it is /lib/libc.so.6 (or something similar.) I want to be able to type some command where "-lc" is the input and "/lib/libc.so.6" is the output. To extend this idea futher, I wanted to specify my own search path so I can use this librar...