.cpp ファイルと .h ファイルから静的リンクのスタンドアロン .exe ファイルを作成する必要があります。
m_pListAll()克服しなければならない唯一の障害は、2 つの .cpp ファイルから同じ関数を呼び出せるようにすることとmain.cpp、window.cpp(というクラスを定義することWindow) です。
唯一の問題は、(理由は不明ですが) #includem_peDO() を定義するヘッダー ファイルを 2 回定義できないことmain.cppとwindow.cpp、1 回しか実行できないことです。これは、ヘッダー ファイルが「動的リンク」と呼ばれるものをHINSTANCE(間違った: 実際の理由は回答セクションにあります):
//linking.h
// This is an extra header file for dynamic linking of the LabJackUD driver.
// support@labjack.com
#ifdef __cplusplus
extern "C"
{
#endif
//For dynamic linking, we first define structures that have the same format
//as the desired function prototype.
typedef LJ_ERROR (CALLBACK *tListAll) (long, long, long *, long *, long *, double *);
//Define a variable to hold a handle to the loaded DLL.
HINSTANCE hDLLInstance;
//Define variables for the UD functions.
tListAll m_pListAll;
#ifdef __cplusplus
} // extern C
#endif
他にも関数はありますが、main.cpp と window.cpp で tListAll m_pListAll を使用したいとします。Qt プロジェクトには次のファイルが含まれています。
main.cpp //main code
window.h //header defining a class used in main
window.cpp //cpp thing defining that class's methods
peripheral.h //header file to control my peripheral device
peripheral.lib //library file to control my peripheral device (VC6 only not minGW?!)
linking.h //thing that solves(?) the minGW/VC6 library incompatibility (read on)
Scenario 1) #include <linking.h> in **only** main.cpp
Outcome: m_pListAll() only in scope of main.cpp, out of scope for window.cpp
Scenario 2) #include <linking.h> in **both** main.cpp AND window.cpp
Outcome: Redefinition errors for redefining hDLLInstance and m_pListAll().
なぜ私はこの奇妙な HINSTANCE を使用しているのですか? 私の.libファイルがminGWと互換性がないことに関係があります。ライブラリをコンパイルの一部として静的に追加すると、次のようになります。 EXE'。止まる。
私は何をすべきか?その関数をwindow.cppのスコープに入れたいだけですが、エラーのためにそのヘッダーを2回使用したくありません。