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++.
641
questions
0
votes
0
answers
36
views
Static and Dynamic Pods not work simultaneously in Podfile React Native
XCode Error Image
I'm currently working on a React Native project that involves the use of multiple Pods. However, I'm encountering an issue when attempting to run the project in Xcode.
The problem ...
1
vote
0
answers
47
views
When does GCC give different typeids in different DSOs?
Using the same version of GCC/Clang, is there a way to ensure typeid gives different results for the same type in two different DSOs, such that dynamic_cast and/or catching an exception across a DSO ...
2
votes
1
answer
414
views
Global variables - When to use static, inline, extern, const, and constexpr
There are plenty of questions and answers relating to C++ global variables, such as:
static and extern global variables in C and C++
Global variables and constexpr (inline or not?)
Is there any sense ...
2
votes
2
answers
55
views
inline keyword causes linker error in Clion
I have a strange error concerning the inline keyword, this is just a sample code I wrote:
#include <stdio.h>
#include <stdint.h>
uint8_t inline LIB_MATH_BTT_u8GetMSBSetBitPos(uint32_t ...
3
votes
1
answer
208
views
What is the real nature of inline keyword in relation to linkages?
I have a serious problem to reconcile the "inline concept" with "linkage" with my humble knowledge:
I've heard we can use extern to access "a non-static entity"
(like an ...
3
votes
1
answer
58
views
External or internal linkage for static class member functions?
I believe a C++ member function declared as static has internal linkage. When I compile libbar.cpp/libbar.hpp (below) as a shared object, I find that I can call both test1 and test2 from a separate (...
0
votes
0
answers
296
views
C++ as a FFI language
I know of many people who initially wrote their programs in C++ instead of C, then decided to package the program's functionality as a library so rewrote it as a library in C so that it may be called ...
0
votes
3
answers
172
views
Use function from other C file by a function pointer
First of all, I'm not sure if the title describes well the problem, feel free to change or suggest a more fitting heading.
I have the following problem:
I need to pass a function pointer to some ...
0
votes
1
answer
90
views
Changing Distance and Linkage of a heat map
I am trying to change the distance and linkage of my heat map from the standard
Euclidean Distance and Complete linkage to any other setting for a question in my homework.
We are using this data set:
...
2
votes
3
answers
360
views
Conflicting C linkage declaration of two functions in different C++ namespaces
In C++ code, I would like to be able to include two headers for two different versions of a shared C library that I load at runtime (with dlopen/dlsym on linux, GetProcAddress on windows).
For one ...
0
votes
1
answer
151
views
Where in C++17 document say that class static member function has external linkage?
I've seen some statements that static member function has external linkage.
However, I cannot find the statement from C++17 official document. Does anyone know?
If anyone provides the line from c++17 ...
5
votes
3
answers
398
views
How can static local variable shared along different translation unit?
How can static local variable shared along different translation unit?
I know that "static" specifies internal linkage.
In case of "static" member function having same address in ...
0
votes
0
answers
28
views
Linkage errors with cmake build to shared system "spdlog" library [duplicate]
Update: I finally could solve this problem on my own after (see below [#Solution]) this post getting automaticaly flagged as CLOSED & some further hours of digging the web & some helpful ...
1
vote
1
answer
119
views
Extern variable define inside namespace LNK2001 Error
I have been running into issues with these externally defined variables in C++ Visual Studio.
I have large data tables that are being compiled into code, rather than read. They are .cpp files defined ...
1
vote
1
answer
135
views
Multiple functions in COBOL Linkage [duplicate]
I'm a C++/Python developer dabbling in COBOL, using open-cobol (cobc) on Linux.
I have several related functions which I would like to keep together. Normally, in COBOL, there is only one function ...
0
votes
0
answers
61
views
How do I read the matrix resulting of a linkage?
I am doing a hierarchical agglomerative clustering. Everything is working fine, but I want to do representation of t vs. number of cluster of the dendrogram.
The only info about the dendrogram is the ...
0
votes
0
answers
38
views
How can I solve linkage error with QList in Qt6.2
while porting from Qt5 to Qt6 I get linkage errors while linking specific project in my solution.
Its happened only with QList types.
1>vNPI.debug_amd64.Dev_2019.AMD64.DFM2DataDef.lib(vNPI....
1
vote
2
answers
111
views
C - One-definition rule for functions
I'm new to C and have read that each function may only be defined once, but I can't seem to reconcile this with what I'm seeing in the console. For example, I am able to overwrite the definition of ...
0
votes
0
answers
58
views
Definition for extern object inside a static member function of the class [duplicate]
So, I have a class A, the declarations for which are placed in the header file "a.h"
class A{
public:
static void init();
void print_hello();
};
extern A obj;
The ...
-1
votes
1
answer
73
views
Is it possible to use a macro defined value in C/C++?
In the LLVM codebase, I see this lines:
class LLVM_EXTERNAL_VISIBILITY Function : public GlobalObject,
public ilist_node<Function> {
My LSP (clangd) ...
2
votes
1
answer
86
views
Implicit class instantiations translation units: multiple definition when linking
I have two static libraries linked in a resulting executable. Both of them identically define the class template fmt::formatter<shatred_ptr<T>,char> template for formatting shared_ptr<T&...
2
votes
1
answer
159
views
Constructing std::function from extern functions gives std::bad_function_call
I am experimenting with making pure Haskell-style I/O in C++. It's working correctly, but when I reorganize some definitions, I run into a std::bad_function_call.
This is about as much as it takes to ...
1
vote
1
answer
152
views
Why are C++ features unable to be used in extern "C" prototypes but able to be used in the implementation to link in C? [duplicate]
Functions in extern "C" are interpreted in C manners, e.g. no name mangling. However, why do C++ features, such as STL, std::string, smart pointer and so on, can be used in the function ...
1
vote
1
answer
289
views
C linkage function cannot return c++ class when converting cpp to dll
After following some simple tutorial, I want to convert my cpp program to a dll file, however, it return several errors, like
C2526'split':c linkage function cannot return c++ class 'std::vector<...
1
vote
1
answer
66
views
c++ compiled object files and internal identifiers
i read here that
A function with internal linkage is only visible inside one translation unit. When the compiler compiles a function with internal linkage, the compiler writes the machine code for ...
0
votes
1
answer
393
views
use extern "C++" with template inside extern "C"
#include <string>
#include <sstream>
#include <iostream>
extern "C" {
struct A {
public:
#ifdef __cplusplus
//extern "C++" {
template<typename T>
...
0
votes
2
answers
62
views
Why don't structures in headers violate ODR across multiple translation units?
From what I understand, the main reason people separate function declarations and definitions is so that the functions can be used in multiple compilation units. So then I was wondering, what's the ...
11
votes
1
answer
2k
views
undefined reference issue with latest gcc
I have link-time error when trying to compile following code with gcc 12.1.0.
With clang, msvc and older gcc it compiles as expected.
template<typename T>
void def()
{}
template<void (*...
-1
votes
1
answer
36
views
Difference between C global and local _static_ variables?
My C is quite rusty, please help me out.
static int i = 42;
int main()
{
}
creates a variable i with global scope and internal linkage. Meaning anyone can refer to it but only entries within the ...
0
votes
3
answers
59
views
Can extern make a function variable a global variable?
As I understood extern makes a variable --> global variable, so it means we can also make variable of another function a global variable?
#include <stdio.h>
extern char* name;
void ...
0
votes
0
answers
28
views
Accessing a file scope variable with internal linkage, in another scope within the same translation unit using extern [duplicate]
I am trying to access the file-scoped variable, defined with internal linkage, inside an inner block in main but the compiler is throwing an error.
error: variable previously declared ‘static’ ...
0
votes
1
answer
418
views
How can I construct a scipy linkage matrix given a binary tree?
I know there's the to_tree() method to convert a linkage matrix to a tree, but how can I do the opposite? Specifically, given a simple nested list representing a binary tree, how do I obtain the ...
0
votes
0
answers
138
views
shm_open gives segmentation fault when it compiled with -static flag
I am trying to build a shared memory application where I can share data between unrelated processes. In my example, POSIX shm_open call works fine if I use the Dynamic linking while building as below
...
0
votes
1
answer
132
views
How does external / internal identifier relate to the linkage?
C2x (and before) uses the following terms w/o a definition: "external identifier" and "internal identifier".
How do these terms relate to the linkage?
Logically:
"external ...
1
vote
1
answer
382
views
Can I extern the entire namespace?
Is there a method to declare a namespace with the extern modifier so that the namespace's entire content is externally linked?
1
vote
1
answer
254
views
Array external linkage and MISRA 8.12
I have a program that needs to load fonts into a display according to language ID.
I would like to have a structure containing the attributes for writing the font data:
typedef struct ...
1
vote
1
answer
154
views
Linking functions with different return types
0.c
int test();
int main(){
return test();
}
1.c
void test(){
//
}
Above compiles fine with gcc 0.c 1.c and main returns 0.
Is this undefined behaviour? as test technically doesn't return anything....
0
votes
1
answer
46
views
Linking to lib on Linux without headers
Hello I'm trying to link to a library without headers. I wrote prototype exactly as defined in library, but ld cannot link it.
readelf -Ws Release/libcef.so | grep KeyStringToDomKey
386822: ...
0
votes
2
answers
762
views
Makefile linking using g++ compiler with CUDA object files
I am trying to compile cuda object files with nvcc, and compile the final main script using the g++ compiler. I have seen this post but wasn't able to get my example working. The error I am getting ...
0
votes
0
answers
810
views
How is it possible to link static libraries with the same symbol?
I have two static libraries foo.a and bar.a. Each library contains the same symbol:
$ nm foo.a | grep _some_symbol
U _some_symbol
0000000000000000 R _some_symbol
$ nm bar.a | grep ...
0
votes
0
answers
13
views
I want to test a simple singleton case and it has a linkage error [duplicate]
I want to test a simple singleton case, write a class C below:
class C {
static C * ptr_c;
C(){}
public:
static C* getInstance()
{
if (ptr_c == nullptr)
ptr_c = ...
2
votes
1
answer
87
views
Why is an implicit extern declaration invalid if there is a prior static declaration?
Consider the following example program:
#include <stdio.h>
static int n = 123;
extern int n;
int main(void) { printf("n is %d\n", n); return 0; }
It compiles successfully with gcc -...
0
votes
0
answers
19
views
C++ Linkage Error using static vectors. shape example [duplicate]
I have a linkage error in this code. can someone solve this problem and explain why does it happen?
Header file
#pragma once
#include <iostream>
#include <vector>
class Shape
{
public:
...
1
vote
1
answer
217
views
How is the inline specifier used in C++ to preserve the one definition rule?
I've been trying to figure out how the inline specifier preserves ODR. So far, with everything I've written it seems unnecessary because include guards ensure that definitions are only included once.
...
0
votes
1
answer
127
views
How external linkage of member functions occurs?
I have two Translation Units with the following codes:
//Translation Unit A
struct A {
void f(int a) {};
};
//Translation Unit B
void f(int j);
int main()
{
f(4);
}
In the translation unit A ,...
1
vote
0
answers
222
views
LNK2005 Error Related to OpenCV When Generating CLR DLL in Visual Studio
Similar to LNK2005 Error in CLR Windows Form, yet this answer cannot explain what I've met.
My question is at the end of the description, thanks for the patience.
The project structure is as below (I ...
27
votes
3
answers
2k
views
Clarification on difference in ODR rules for structs in C and C++
I am aware of how ODR, linkage, static, and extern "C" work with functions. But I am not sure about visibility of types since they cannot be declared static and there are no anonymous ...
-1
votes
1
answer
192
views
does c++ allows hoisting or is it compiler specific ? even if
So i was looking through various questions to prepare for my interview that's up tomorrow and came across extern keyword, i understand that extern keyword specifies to allocate memory for a variable ...
-1
votes
1
answer
276
views
Define variable in one file but it's undefined in another (declared in common header)
I have some functionality which is highlighted in a separate file functionality.c. The code in this file reads thresholds which are in functionality.h:
unsigned int thresold1[2];
unsigned int ...
2
votes
2
answers
253
views
Real Applications of internal linkage in C++
This sounds like a duplicate version of What is the point of internal linkage in C++ and probably is. There was only one post with some code that didn't look like a practical example. C++ISO draft ...