extern

What are the different ways of specifying the linking path to FFI libraries in Rust?

此生再无相见时 提交于 2019-12-11 12:37:43
问题 Using the below code as an example: extern crate libc; #[link(name = "adder")] extern { fn double_input(input: libc::c_int) -> libc::c_int; } fn main() { let input = 4; let output = unsafe { double_input(input) }; println!("{} * 2 = {}", input, output); } Should #[link(name = "adder")] include a relative path to the .o / a / .h files? For example, should it be #[link(name = "../adderlib/adder")] ? Is there another way to tell the compiler where adder is? 回答1: The answer to the first question

How to provide custom implementation for extern methods in .NET?

半世苍凉 提交于 2019-12-11 09:06:37
问题 In C# the extern modifier is used to declare a method that is implemented externally. Usually it is used with DllImport attribute to call some function in unmanaged code. I wonder if there is a way to provide custom implementation of extern method? To understand better the problem consider the following use case. I have a set of functions implemented in unmanaged code and I'd like to supply pointers to these function in run-time (during the loading of assembly). The same thing DllImport

How to build a compiler-independent C++ library (for Solaris Studio and gcc)?

一世执手 提交于 2019-12-11 06:57:12
问题 I would like to extend my library, which currently compiles only using gcc, to be used by Solaris Studio as well. My idea is to do the following: Write wrapper functions in C, which expose the relevant parts of the interface with extern C linkage. Then build this library using gcc. The resulting c-header and binary are compiler independent as there is no name mangling anymore. Include the c-header and link into the project compiled with Solaris Studio. Question: Is this a feasible approach or

Accessing a global variable defined in a .cpp file in another .cpp file [duplicate]

断了今生、忘了曾经 提交于 2019-12-11 06:15:17
问题 This question already has an answer here : Access extern variable in C++ from another file (1 answer) Closed 9 months ago . Consider the following scenario: MyFile.cpp : const int myVar = 0; // global variable AnotherFile.cpp : void myFun() { std::cout << myVar; // compiler error: Undefined symbol } Now if I add extern const int myVar; in AnotherFile.cpp before using, linker complains as Unresolved external I can move the declaration of myVar to MyFile.h and include MyFile.h in AnotherFile

trouble accessing external float array

陌路散爱 提交于 2019-12-11 05:14:43
问题 I have the following program in two files main.cpp float POW10[300]; main(0 { Fill_POW10(); } Fill.cpp extern float *POW10; Fill_POW10() { for(int i=0;i<300;i++) { POW10[i]=i; } } This crashed with a segmentation fault. When I inspect, POW10 is NULL. However if I change Fill.cpp to extern float POW10[]; Fill_POW10() { for(int i=0;i<300;i++) { POW10[i]=i; } } the code works fine. I was thinking that POW10 is actually implemented as a pointer to floats and so the codes should be identical. Can

How to define an extern, C struct returning function in C++ using MSVC?

浪尽此生 提交于 2019-12-11 04:02:59
问题 The following source file will not compile with the MSVC compiler (v15.00.30729.01): /* stest.c */ #ifdef __cplusplus extern "C" { #endif struct Test; /* NB: This may be extern when imported by another module. */ struct Test make_Test(int x); struct Test { int x; }; struct Test make_Test(int x) { struct Test r; r.x = x; return r; } #ifdef __cplusplus } #endif Compiling with cl /c /Tpstest.c produces the following error: stest.c(8) : error C2526: 'make_Test' : C linkage function cannot return

LLVM Kaleidoscope tutorial failing on local extern

寵の児 提交于 2019-12-11 03:52:29
问题 I am working through the LLVM Kaleidoscope tutorial. Everything is working fine except for local externs (as opposed to things like the math functions). [c34n10 kaleidoscope] ./toy ready> extern sin(x); sin(1); ready> Read extern: declare double @sin(double) ready> ready> Evaluated to 0.841471 ready> extern putchard(x); putchard(120); ready> Read extern: declare double @putchard(double) ready> ready> Failure value returned from cantFail wrapped call UNREACHABLE executed at /gpfs/loomis

Why including an h file with external vars and funcs results in undefined references

為{幸葍}努か 提交于 2019-12-11 03:32:49
问题 What if I want these externals to be resolved in runtime with dlopen? Im trying to understand why including an h file, with shared library external vars and funcs, to a C executable program results in undefined/unresolved. (when linking) Why do I have to add "-lsomelib" flag to the gcc linkage if I only want these symbols to be resolved in runtime. What does the link time linker need these deffinitions resolutions for. Why cant it wait for the resolution in runtime when using dlopen. Can

How to compile Freetype (2) and Harfbuzz (with visual studio) to make them work together?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 01:58:42
问题 I have found good documentations on this known problem of compiling Freetype related to Harfbuzz: http://www.gregwessels.com/dev/2017/05/02/freetype-harfbuzz.html and here 44184890 But they seem obsolet nowadays: freetype-2.9 with harfbuzz-1.7.6 Here is my way compiling: download Freetype tarball extract the tarball... open builds\windows\vc2010\freetype.sln it should already Generate well (as a dll) download Harfbuzz extract the tarball next to freetype... run cmake ./ at root level to

Objective-C – access extern const with a string containing its name? [duplicate]

走远了吗. 提交于 2019-12-10 23:50:10
问题 This question already has an answer here : How do I lookup a string constant at runtime in Objective-C? (1 answer) Closed 4 years ago . I have a constant defined out of class in SomeClass.h: extern NSString *const SCImportantString; @interface SomeClass @end And assign it in SomeClass.m: NSString *const SCImportantString = @"All your base are belong to us."; @implementation SomeClass @end Is there a way to access this extern constant by a string with its name? I know this is possible with