問題タブ [extern-c]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 変数の extern および extern "C"
C プログラムで使用する C++ 共有ライブラリを作成しています。しかし、 と について質問がextern
ありextern "C"
ます。
次のコードを検討してください
私のヘッダーファイルは次のようなものです:
これは問題なく動作します。宣言するしかない
私の.cppまたは私の.cファイルのいずれかで。ただし、私が理解していないのは次のとおりです。
extern "C"
とここはどう違いextern
ますか?コメントアウトしてみましたがextern "C" int global
、うまくいきました!なんで?
私はそれextern "C"
がCリンケージを作るために使われていることを知っています。それが私が持っている理由ですextern "C" int addnumbers(int,int)
。つまり、C プログラムで使用する C++ 関数を書きたい場合は、extern "C"
. さて、グローバル変数についてはどうですか - ここでは状況が違うと思いますか? C プログラムで という名前の C++ 変数を使用したいのですが、global
使用できextern
ませんextern "C"
。何故ですか?これは私には直感的ではありません。
コメント: 変数と関数に使用する場合の違いを尋ねているので、これは重複しているとは思いません。
c++ - linking to C++ libraries to Modelica
I'm trying to utilize a C++ library in Modelica. Modelica compilers generate c from Modelica source and then invokes a c compiler to create an executable. Modelica provides a mechanism to call c functions. I've created a wrapper:
External C code is either linked dynamically to the Modelica executable or if the code is pure c, it can be compiled right with the generated c. The only option I have here is to go the dynamic link route. Here's the Makefile for building the C++ library
When I run the Modelica compiler I get some link errors that due to the fact that there are c++ libraries that need to be dynamically linked.
Is there a way to build libmywrappedcpp.so so that the c compiler invoked by the Modelica system won't have to try to link c++?
ios - unity3d から iOS にデータを渡すときに別のビューコントローラーをプッシュできない
データを渡すために、unity 3d と iOS の間にブリッジがあります。extern "C" を使用して unity 3d から iOS にデータを正常に送信できます。その後、extern "c" のメソッドから目的の c メソッドを呼び出すことができます。しかし、目的のCメソッドから、別のビューコントローラーをプッシュしたい場合、クラッシュして次の問題が表示されます。
この問題を解決するにはどうすればよいですか?
これが私のView Controllerクラスです: