Questions tagged [linkage]

Linkage describes how names can or can not refer to the same entity throughout the entire program or a single unit. Linkage is particularly useful in C++.

The static keyword is used in to restrict the visibility of a function or variable to its translation unit. This is also valid in .

A name's linkage is related to, but distinct from, its . The scope of a name is the part of a translation unit where it is visible. For instance, a name with global scope (which is the same as file-scope in C and the same as the global namespace-scope in C++) is visible in any part of the file. Its scope will end at the end of the translation unit, whether or not that name has been given external or internal linkage.

If the name has external linkage, the that name denotes may be referred to from another translation unit using a for that same name, and from other scopes within the same translation unit using distinct declarations. Were the name given internal linkage, such a declaration would denote a distinct entity, although using the same name, but its entity could be referred to by distinct declarations within the same translation unit. A name that has no linkage at all cannot be referred to from declarations in different scopes, not even from within the same translation unit. Examples of such names are parameters of functions and local variables. The details differ between C (where only objects and functions - but not types have linkage) and C++ and between this simplified overview.

Static Linking

In static linking, the compiled functions are stored into the executable or dynamic library (if you're creating one).

Dynamic Linking

In dynamic linking, the compiled function is stored in a separated library (DLL in Windows or shared object in Linux). A small piece if code is added to the executable to load that shared library at runtime and map the public functions and variables within it.

639 questions
0
votes
4 answers

Rails and SQLITE: Images are not being displayed

I am very new to Rails and Web-programming and hope you can help me out with my very first project. I am developing a website for a Real Estate Agency. I have 3 tables in my database (Homes: Home_ID, Home_Name, Admin_ID; Admins: Admin_ID,…
Ron
  • 69
  • 2
  • 7
0
votes
2 answers

Can DirectX11 Dynamic Shader Linkage be used without Shader Reflections?

I tried to implement dynamic shader linkage from what I saw in the DirectX11 SDK,but they are using the Effects11 framework and shader reflections.I'm trying to get a cleaner more low-level implementation.For instance - for constants buffer instead…
ulak blade
  • 2,515
  • 5
  • 37
  • 81
0
votes
1 answer

C++ Standard regarding external linkage and calling conventions

I've read the last C++11 draft (n3337 - is it the last one?), and I got a question for a possible implementation I've been working on. Let's say we have this code: extern "Objective C" { class Object { public: static Object *alloc(); …
paulotorrens
  • 2,286
  • 20
  • 30
0
votes
4 answers

Use of extern in translation unit

extern int a; int a = 1; int main(void) { return 0; } Is this UB? standard says in 6.2.2/7 If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
0
votes
2 answers

Create Sprite derived symbols using linkage

Just found it is possible to give a linkage in Flash Professional IDE for symbols that has Sprite class as parent. Previously I was sure the only option is MovieClip. The question is: How to make these symbols to play animation at runtime? When I…
Oleksiyka
  • 1
  • 1
0
votes
1 answer

C++: Name and linkage of what I'm doing?

Looking for the official name and the linkage type of this type of template specialization where we're specializing a template only to specialize the implementation of a single method within a class template. template class Foo { public: …
stinky472
  • 6,737
  • 28
  • 27
0
votes
1 answer

separate compilation in C gives error if function is declared in header file

I have a problem compiling separate module in C with gcc: basically, i have my header, common.h: #ifndef COMMON_M #include #define COMMON_M void print_array(int *a,int n); void swap(int *v,int i,int j); #endif my…
sowdust
  • 87
  • 1
  • 9
0
votes
2 answers

Can't link static lib for android NDK, cygwin gcc

I have PROJ4 library, succesfully compiled under cygwin and installed to /usr/local. I'm trying to compile as: $ arm-linux-androideabi-gcc -o conftest -mthumb temp.c -lproj -L/usr/local/lib -lproj -lz -lm…
Frederic Blase
  • 510
  • 1
  • 4
  • 15
0
votes
1 answer

Remove Linkage in the other Scenes?

I wanted to have a class linkage of my MovieCip in the first scene. But when i go to second Scene, i don't want anymore this linkage.
ig.
  • 15
  • 1
  • 1
  • 8
0
votes
1 answer

UML object attribute linkage

If you've got a function like this inside a class called 'A' public updateResponse(UpdateRequest updateRequest){ //... } Where UpdateRequest is another class which you create an object from as in UpdateRequest ur = new UpdateRequest(); What is…
Gooey
  • 4,740
  • 10
  • 42
  • 76
0
votes
1 answer

GCC global variable storage

Is it possible to force gcc to store an array in a specific segment? I want this static const Host_Vtable_Entrty…
user877329
  • 6,717
  • 8
  • 46
  • 88
0
votes
0 answers

linkage conventions, how to declare qsort

I would like to ask how to declare qsort function from stdlib.h in a different compilation unit and avoid warning about inconsistent dll linkage. typedef int (*FT)(const void*, const void*); //FT has C++ linkage extern "C"{ typedef int (__cdecl…
4pie0
  • 29,204
  • 9
  • 82
  • 118
0
votes
1 answer

c and c++ linkage with libraries

Suppose I have a C++ library lib.h that uses classes and templates. Suppose also that I have a custom C++ header myLink.h with the following: #include "lib.h" //call methods from lib.h that use templates and classes // and return an integer…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
0
votes
2 answers

Visual Studios 9 Inconsistent Dll linkage

Basically the line of code extern char *strlwr OF((char *s)); gives the error warning C4273: 'strlwr' : inconsistent dll linkage and I don't know why. It's not my code so I'm having issues figuring out how to fix it.
SSEMember
  • 2,103
  • 4
  • 20
  • 28
0
votes
1 answer

gcc undefined _cxa_pure_virtual

I have 2 shared object libs and one executable. 1 of the libs that I compile has linkage error: Undefined _cxa_pure_virtual. Why? Usually we do not need to implement it. Any Ideas? If I implement it both the libs compile and link OK, but the…
user1365799
  • 83
  • 1
  • 10