デバイスのAPIのdllを書きたいと思います。私はdllの初心者なので、単純なテキストエディタで実装し、api用に作成したかったのです。 ヘッダファイルとcppファイルを作成しましたが、コードを実行するとエラーlnk2001が発生し、lnk1120が未解決の外部エラーです。C++ DLLリンカエラー
私は間違いをどこでやったのか分かりません。私は正しい方法で行っています。あなたが私を助けることができるかどうか疑問に思っていました。 tnx。
は、ここに私のヘッダファイル
// EditFuncsDll.h
#include <cstdio>
#include <vector>
#include <string>
namespace EditFuncs
{
class MyEditFuncs
{
private:
static std::vector<std::string> MyTextBox;
public:
static __declspec(dllexport) void Load(std::string command);
static __declspec(dllexport) void Save(std::string command);
static __declspec(dllexport) int Lines();
static __declspec(dllexport) void Add(std::string command);
static __declspec(dllexport) void Remove(std::string command);
static __declspec(dllexport) void Insert(std::string command);
static __declspec(dllexport) int wc(std::string command);
static __declspec(dllexport) void GetInfo();
};
}
で、私のcppファイルに私はちょうど私がヘッダファイルで宣言された関数を定義します。
、これらは私が
エラー25エラーLNK2001取得エラーです:未解決の外部シンボル「プライベート:静的クラスのstd ::ベクトル、クラスのstd ::アロケータ>、クラスのstd ::アロケータ、クラスのstd "MyTextBox @ MyEditFuncs @ EditFuncs @@ 0V?$ vector @ V?$ basic_string @ DU?$ char_traits @ D @ std @@ V?$ allocator @D @ 2 @@ std @@ V?$ allocator @ V?$ basic_string @ DU?$ char_traits @D @ std @@ V?$ allocator @D @ 2 @ std @@@ 2 @@ std @@ A)C: \ Users \ Lucy \ Desktop \ Erfan \ Text_Editor_DLL \ Text_Editor_DLL \ EditFuncsDll.obj Text_Editor_DLL
および
エラー26エラーLNK1120:1つの未解決の外部C:\ Users \ユーザールーシー\デスクトップ\ ERFAN \ Text_Editor_DLL \デバッグ\ Text_Editor_DLL.dll Text_Editor_DLL
@Assemんだけど、これがあるのcppファイル内の関数を定義していますメインのcppではなくヘッダのcppファイル。私はそこに定義するべきだとは思わない。したほうがいい? – Erfan
対応するcppで宣言されたすべての静的メンバー変数を定義する必要があります。 .cppファイル内の関数の定義の前に記述してください。 私は前のコメントに書いたものを修正する必要があります: std :: vector EditFuncs :: MyEditFuncs :: MyTextBox; – Assem
@Assem ここに私のcppの一部です '// EditFuncsDll.cpp #include "EditFuncsDll。H」 の#include の#include 名前空間stdを使用して、 名前空間EditFuncs { \t静的のstd ::ベクトル MyTextBoxを、 \t空隙MyEditFuncs ::負荷(stringコマンド) \t { \t \tストリングファイル名; \t \t //ファイルの名前はコマンドの5文字目から始まり、最後に移動します \t \tファイルname = command.substr(5、command.size()); \t \t ifstream inFile; \t \t inFile.open(filename); ' あなたが言ったことによると、私はその静的変数の定義を追加しましたが、それでも私は同じエラーを受け取ります。なぜか分からない! –
Erfan