• ベストアンサー

LNK2019: 未解決の外部シンボルのエラーが出る

Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM Microsoft .NET Framework Version 3.5 SP1 ---------------------------------------------------------------- 新しいプリジェクト→Win32 コンソール アプリケーション(ソリューションのディレクトリを作成 チェック外す)→Windows アプリケーション(空のプロジェクト チェック外す) ----------------------------------------------------------------  プログラム  mymain.cpp #include "myhelper.h" #include "mymain.h" //自キャラのデータ Point2D g_jikipos = {40, 400}; //自キャラの座標 //画像ハンドル int g_jikiimage[11]; //色々なファイルの読み込み int LoadFiles(){ //画像ファイル読み込み if(LoadDivGraph("media\\player01.bmp", 11,11,1,64,64,g_jikiimage) == -1) return -1; return 1; }  mymain.h //他から呼び出させるMyMainの関数 void MyMain(); int LoadFiles();  myhelper.h(サンプルなので打ちミスはない) #include "DxLib.h" #include <limits.h> #include <math.h> //構造体宣言 //座標またはベクトルを記録する構造体 struct Vector{ float x,y; }; typedef Vector Point2D; //線を記録する構造体 struct Line2D{ Point2D startpos, endpos; float katamuki; //傾きをラジアン値で記録 Vector speed; //移動している場合は速度をセット }; //球体を記録する構造体 struct Ball2D{ Point2D position; float hankei; //半径 }; //四角形を記録する構造体 struct Rect2D{ Point2D lefttop; Point2D rightbottom; float width; float height; }; //ライブラリ関数 Point2D PosInView(Point2D in); int XInView(float inx); int YInView(float iny); void ScrollToLeft(float jikiposx); void ScrollToRight(float jikiposx); void ScrollToUp(float jikiposy); void ScrollToDown(float jikiposy); void DrawLineInView(float x1, float y1, float x2, float y2, int Color, int Thickness); void DrawCircleInView(float x, float y, float r, int Color, int FillFlag); void DrawAnimation(float x, float y, double ExtRate, double Angle,int TurnFlag, int *imgarray, int allframe, float fps); //ベクトル関数 Vector CreateVector(Vector in, float veclen); Vector AddVector(Vector v1, Vector v2); Vector SubVector(Vector v1, Vector v2); Vector AddVectorInFrameTime(Vector pos, Vector speed); Vector AddVectorInFrameTime2(Vector pos, Vector speed, Vector accel); Vector Normalize(Vector in); Vector RotateVector(Vector in, float radian); float VectorLengthSquare(Vector in); float DotProduct(Vector v1, Vector v2); float CrossProduct(Vector v1, Vector v2); void SetLine2DKatamuki(Line2D *in); void DrawLine2D(Line2D in, int Color, int Thickness); void DrawBall2D(Ball2D in, int Color, int Fill); //当たり判定関数 bool HitTestLineAndBall(Line2D linein, Ball2D ballin); bool IsPointAtLineFace(Line2D linein, Point2D ptin); bool HitTestLineAndLine(Line2D line1, Line2D line2); bool HitTestBallAndBall(Ball2D a, Ball2D b); bool HitTestPointAndBox(Rect2D rect, Point2D pt); //タイマー関数 void SetSimpleTimer(int idx, int time); int GetPassedTime(int idx); //グローバル変数 extern float g_frametime; extern Rect2D g_framerect; //画面領域(当たり判定) extern Point2D g_current_field_pos; //現在の左上座標 extern Rect2D g_stagesize; //ステージサイズ //定数宣言 const float ZEROVALUE = 1e-10f; const float PIE = 3.1415926f; const int SCROLL_LIMIT = 200; ----------------------------------------------------------------  エラー内容 1>myhelper.obj : error LNK2019: 未解決の外部シンボル "void __cdecl MyMain(void)" (?MyMain@@YAXXZ) が関数 _WinMain@16 で参照されました 1>C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\Projects\my\Debug\my.exe : fatal error LNK1120: 外部参照 1 が未解決です 1>my - エラー 2、警告 0 ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ---------------------------------------------------------------- 画像を貼り付けときます (見えにくい場合→http://www.dotup.org/uploda/www.dotup.org154142.jpg.html) 初心者なのでわかりやすくお願いします

質問者が選んだベストアンサー

  • ベストアンサー
  • php504
  • ベストアンサー率42% (926/2160)
回答No.2

ファイル構成から推測するに mymain.cpp というファイルに void MyMain(void) { // ここに処理を書く } という関数が必要なようです。

sakana20zb
質問者

お礼

とりあえず、追加したところエラーはおきませんでした。 ですが、何も映らない・・・ ん~後はこれに何かつけくわえればいいのかな・・・ アドバイスありがとうございます。

sakana20zb
質問者

補足

書き足りなかったところを・・・ ----------------------------------------------------------------  -プロパティー - 構成(アクティブ) 文字セット→マルチバイト、コード生成→マルチデバック(/MTd) 構成(Relesae) 文字セット→マルチバイト、コード生成→マルチスレッド(/MT) ----------------------------------------------------------------  -ツール→オプション- VC++ディレクトリ。インクルードファイル C:\Documents and Settings\Owner\デスクトップ\ゲーム製作\kaihatsu\DxLib_VC\プロジェクトに追加すべきファイル_VC用 を追加。 続いて、ライブラリファイル。 :\Documents and Settings\Owner\デスクトップ\ゲーム製作\kaihatsu\DxLib_VC\プロジェクトに追加すべきファイル_VC用 を追加 ---------------------------------------------------------------- myファイル中にちゃんと入ってます。 マイドキュメント\Visual Studio 2008\Projects\my\ myhelper.h mymain.h mymain.cpp myhelper.cpp media\player01.bmp ---------------------------------------------------------------- DXライブラリ、ソースコード、画像は http://www.rutles.net/download/217/index.html ここからDLしてきたものです 本どおりに設定しているので間違ってるとは思えないんですけどね・・・

その他の回答 (2)

  • asuncion
  • ベストアンサー率33% (2126/6286)
回答No.3

>未解決の外部シンボル このリンクエラーは、当該の関数なり変数なりを 「宣言はしているが定義していない」というときに起きます。 当該の関数や変数を定義してください。

sakana20zb
質問者

お礼

なるほど・・・ちょっと見てきます。 まだ初心者なので時間かかるかもですが・・・ アドバイスありがとうございます

sakana20zb
質問者

補足

ちょっとここに書くのもなんだけど・・・ やっと原因わかりました! php504さんの >void MyMain(){ が見事ビンゴしておりました。 まさか次のページじゃないと動かせないとは・・・ 皆さんお答え頂ありがとうございます!

回答No.1

//他から呼び出させるMyMainの関数 void MyMain(); となっていますが、その本体が無いですね (これは宣言なので、「こういう関数があるよ」って教えているだけです)

sakana20zb
質問者

お礼

お答えありがとうございます。 本体とは、ファイルのことなのか。 確かにないですね・・・ ん~、まだいまいちわかりません(。´Д⊂)

関連するQ&A

  • コンパイルすると error C1083 が出てしまいます

     -スペック- Microsoft Visual Studio 2008 Version 9.0.21022.8 RTM Microsoft .NET Framework Version 3.5 SP1 ---------------------------------------------------------------- 以下のプログラムを実行すると、error C1083: include ファイルを開けません。'myhelper.h': No such file or directory っていうエラーが出ます。 ----------------------------------------------------------------  -プログラム-  - mymain.cpp の中身 - #include "myhelper.h" #include "mymain.h" //自キャラのデータ Point2D g_jikipos = {40, 400}; //自キャラの座標 //画像ハンドル int g_jikiimage[11]; //色々なファイルの読み込み int LoadFiles(){ //画像ファイル読み込み if(LoadDivGraph("media\\player01.bmp", 11,11,1,64,64,g_jikiimage) == -1) return -1; return 1; }  - mymain.h の中身 - //他から呼び出させるMyMainの関数 void MyMain(); int LoadFiles();  - myhelper.h の中身 - #include "DxLib.h" #include <limits.h> #include <math.h> //構造体宣言 //座標またはベクトルを記録する構造体 struct Vector{ float x,y; }; typedef Vector Point2D; //線を記録する構造体 struct Line2D{ Point2D startpos, endpos; float katamuki; //傾きをラジアン値で記録 Vector speed; //移動している場合は速度をセット }; //球体を記録する構造体 struct Ball2D{ Point2D position; float hankei; //半径 }; //四角形を記録する構造体 struct Rect2D{ Point2D lefttop; Point2D rightbottom; float width; float height; }; //ライブラリ関数 Point2D PosInView(Point2D in); int XInView(float inx); int YInView(float iny); void ScrollToLeft(float jikiposx); void ScrollToRight(float jikiposx); void ScrollToUp(float jikiposy); void ScrollToDown(float jikiposy); void DrawLineInView(float x1, float y1, float x2, float y2, int Color, int Thickness); void DrawCircleInView(float x, float y, float r, int Color, int FillFlag); void DrawAnimation(float x, float y, double ExtRate, double Angle,int TurnFlag, int *imgarray, int allframe, float fps); //ベクトル関数 Vector CreateVector(Vector in, float veclen); Vector AddVector(Vector v1, Vector v2); Vector SubVector(Vector v1, Vector v2); Vector AddVectorInFrameTime(Vector pos, Vector speed); Vector AddVectorInFrameTime2(Vector pos, Vector speed, Vector accel); Vector Normalize(Vector in); Vector RotateVector(Vector in, float radian); float VectorLengthSquare(Vector in); float DotProduct(Vector v1, Vector v2); float CrossProduct(Vector v1, Vector v2); void SetLine2DKatamuki(Line2D *in); void DrawLine2D(Line2D in, int Color, int Thickness); void DrawBall2D(Ball2D in, int Color, int Fill); //当たり判定関数 bool HitTestLineAndBall(Line2D linein, Ball2D ballin); bool IsPointAtLineFace(Line2D linein, Point2D ptin); bool HitTestLineAndLine(Line2D line1, Line2D line2); bool HitTestBallAndBall(Ball2D a, Ball2D b); bool HitTestPointAndBox(Rect2D rect, Point2D pt); //タイマー関数 void SetSimpleTimer(int idx, int time); int GetPassedTime(int idx); //グローバル変数 extern float g_frametime; extern Rect2D g_framerect; //画面領域(当たり判定) extern Point2D g_current_field_pos; //現在の左上座標 extern Rect2D g_stagesize; //ステージサイズ //定数宣言 const float ZEROVALUE = 1e-10f; const float PIE = 3.1415926f; const int SCROLL_LIMIT = 200; myhelper.h はコピペなので間違ってはない。 ---------------------------------------------------------------- まだC言語初心者なので、どのようにすれば直せるのかわからないので 詳しくお願いします。 一応サイトで検索などをして、自分なりに調べてきて 定義が間違ってないかを見ましたけどそれでもまだわかりません。 それでは宜しくお願いします。

  • 外部シンボル未解決

    学習のため勉強していますが test3.obj : error LNK2001: 外部シンボル ""int * g_array" (?g_array@@3PAHA)" は未解決です。 となります。リンクエラーだと解りましたが、どこに問題があるのかわかりません。 ソースは以下のとおりです。よろしくお願いします。 【stdafx.h】 #include "targetver.h" #include <tchar.h> #ifndef _TEST4_H_ #define _TEST4_H_ #include <stdio.h> #include <stdlib.h> #include <time.h> const int MAXARRAY = 30; extern int g_array[MAXARRAY]; void printArray(); #endif #include "stdafx.h" 【test3.h】 int _tmain(int argc, _TCHAR* argv[]) { //配列の初期化 srand((unsigned int)time(NULL)); for(int i = 0; i < MAXARRAY; i++) { g_array[i] = rand() % 1000; } printArray(); return 0; } 【test4.h】 #include "stdafx.h" void printArray() { for(int y = 0; y < MAXARRAY/10; y++) { for(int x = 0; x < 10; x++) { int i = y * 10 + x; printf("%3d ", g_array[i]); } printf("\n"); } }

  • C言語のエラー LNK1120: 外部参照

    #include "myhelper.h" #include "mymain_4.h" //自キャラのデータ Point2D g_jikipos = {40, 400}; //画像ハンドル int g_jikiimage[11]; //色々なファイルの読み込み int LoadFiles() { //画像ファイルの読み込み if (LoadDivGraph("media\\player01.bmp", 11, 11, 1, 64, 64, g_jikiimage) == -1) return -1; return 1; } .obj : error  LNK2019: 未解決の外部シンボル (?MyMain_4@@YAXXZ) が関数 _WinMain@16 で参照されました。   error LNK1120: 外部参照 1 が未解決です。      .exeファイル この記述の時、こういったエラーに見舞われます。 プログラムの記述でしょうか? ネットで調べ、ファイルの形式をWIN32コンソールアプリケーションに変えても、 エラーが取れませんでした。   何か方法があればと思い質問します。  VC++の2010を使っています。

  • error LNK2001について

    C++ の勉強中です。 error LNK2001問題がありました。問題点も分からないから、 分かった方に教えていただけないでしょうか? ソースも添付します。環境はVS2005 express edition まず、ヘッダファイルです。ファイル名は、myheader.h #ifndef __MYHEADER_H__ #define __MYHEADER_H__ #define includeshow(x) \ { \ s.show(x); \ } class Sample{ public: void show(char * parameter); }; extern Sample s; #endif //------------------------------------------------ 次に、Sample.cppです。 #include "myheader.h" #include <stdio.h> void Sample::show(char *parameter){ printf("in show func"); } //----------------------------------------------- 最後にTest.cppです。 #include "myheader.h" #include <stdio.h> int main(){ includeshow("ppppp"); } これで error LNK2001: 外部シンボル ""class Sample s" (?s@@3VSample@@A)" は未解決です。というエラーが出ています。 よろしくおねがいします。

  • 未解決の外部シンボル

    ソースはvc++2005からVC++.net2003に各ソースをコピペしてビルドしてみたら EmptyProject.obj : error LNK2019: 未解決の外部シンボル "struct IDirect3D9 * __cdecl DXUTGetD3DObject(void)" (?DXUTGetD3DObject@@YAPAUIDirect3D9@@XZ) が関数 "bool __stdcall IsDeviceAcceptable(struct _D3DCAPS9 *,enum _D3DFORMAT,enum _D3DFORMAT,bool,void *)" (?IsDeviceAcceptable@@YG_NPAU_D3DCAPS9@@W4_D3DFORMAT@@1_NPAX@Z) で参照されました。 EmptyProject.obj : error LNK2019: 未解決の外部シンボル "int __cdecl DXUTGetExitCode(void)" (?DXUTGetExitCode@@YAHXZ) が関数 _WinMain@16 で参照されました。     ・     ・      ・  というエラーがでました。どうしたら通りますでしょうか?

  • fatal error LNK1120: 外部参照 1 が未解決です

    またわからないことが・・・ 教えて下さい。 以下をVC++2005でコンパイルすると、 MSVCRTD.lib(crtexew.obj) : error LNK2019: 未解決の外部シンボル _WinMain@16 が関数 ___tmainCRTStartup で参照されました。 C:\Documents and Settings\tomato\My Documents\Visual Studio 2005\Projects\a\Debug\a.exe : fatal error LNK1120: 外部参照 1 が未解決です。 と警告がでて通りません。 何のことでしょうか。 #include<stdio.h> #include<process.h> struct meibo{   char name[20];   char tel[20];   char address[20]; }; void message( void ); void input( FILE *fp, int cnt , struct meibo *a, int *end ); void main( void ) {   struct meibo a[20];   FILE *fp;   int cnt, end;   if( (fp=fopen( "meibo.dat", "w" ) ) == NULL ){     printf( "Can not open the meibo.dat.\n" );     exit( 1 );   }   message();   fprintf( fp, "番号, 名前, TEL, 住所\n" );   fflush( fp );   cnt = 0;   end = 0;   while( end == 0 ){     input( fp, cnt, &a[cnt], &end );     cnt++;     fflush( fp );     if( cnt == 20 ){       printf( "人数が一杯です.終了します.\n" );       end = 1;     }   }   fclose( fp ); } void message( void ) {   printf( "名前, TEL, 住所, endを入力してください.\n" );   printf( "継続の時はend=0," );   printf( "中止の時は,end=1と入力してください.\n" ); } void input( FILE *fp, int cnt, struct meibo *a, int *end ) {   printf( "名前-->" );   scanf( "%s", a->name );   printf( "TEL -->" );   scanf( "%s", a->tel );   printf( "住所-->" );   scanf( "%s", a->address );   printf( "Exit? Continue:0 Exit:1 -->" );   scanf( "%d", end );   printf( "\n" );   fprintf( fp, "%2d, %s, %s, %s\n",     cnt+1, a->name, a->tel, a->address ); }

  • c言語 クラスの中でvectorをクラスに使う

    C++の質問です。クラスの中でクラスをベクターで使うことはできますでしょうか? 画像にペイントしたものをラインごとに保存するプログラムを作っています。 わからないことは 1、ベクターで宣言したクラスの中身を個別にアクセスしたい。 たとえば linesのpointにはA lineにはBといようにアクセスしたいです。 説明がうまくできませんがアドバイスいただけたら助かります。 以下がソースになります。 =line.h========================================================= class paintedline{ public: //左上座標 Tvector2<int> point; //上下左右の保存 int top,botton,left,right; //線の格納 vector<Tvector3<int>> line; paintedline(); }; =linegroup.h========================================================= #include "icg.h" #include"line.h" class line_group{ float choosing_line; public: vector<paintedline> lines; line_group(); //線を保存--------------クリックしてから離すまで void saveline(Tvector2<int>point, vector<Tvector3<int>> line); //線を決定--------------クリックして線を決定 int return_line(Tcolor4<float> color); //線を移動 void move_line(Tvector2<int>pa, Tvector2<int>pb); //線を削除 void delete_line(); //すべての線をpaintedに合成 void synthesizing_lines(); }; =linegroup.cpp========================================================= #include"linegroup.h" #include"line.h" line_group::line_group(){ } //線を保存--------------クリックしてから離すまで void line_group::saveline(Tvector2<int>point, vector<Tvector3<int>> line){ //線の四隅を保存 for(int i=0; i<(int)line.size(); i++){ if(top>line.y) top = line.y; if(botton<line.y) botton = line.y; if(left>line.x) left = line.x; if(right<line.x) right = line.x; } //書かれた線を保存 lines.push_back(line) } //線を決定----------------クリックして線を決定 int line_group::return_line(Tcolor4<float> color){ choosing_line = color.r// rに格納したばんごうを決定 return choosing_line } //線を移動 void line_group::move_line(Tvector2<int>pa, Tvector2<int>pb,){ int x = abs(pa.x - pb.x); int y = abs(pa.y - pb.y); lines.at(n).point = (x,y); synthesizing_lines(); } //線を削除 void line_group::delete_line(){ cout<<"deleteするならdを押してください。"<<endl; lines.erace(choosing_line); }

  • 「外部シンボルが未解決」について教えてください

    BCCを使ってます。windowsのプログラムで、『外部シンボル 'MyCreateFontが未解決』と言うメッセージが出たのですが、リンクエラーなのでしょうか? また、『外部シンボル○○が未解決』と表示された場合、どのような処置をすればいいですか。アドバイスをお願いします。 D:\borland\bcc55\lesson>bcc32 -W -w-8057 timer.cpp Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland timer.cpp: Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland Error: 外部シンボル 'MyCreateFont(int, unsigned long, const char *)' が未解決(D:\BORLAND\BCC55\LESSON\TIMER.OBJ が参照 ) こちらが、宣言の部分です。 #include <windows.h> #define ID_MYTIMER 100 LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); ATOM InitApp(HINSTANCE); BOOL InitInstance(HINSTANCE, int); HFONT MyCreateFont(int, DWORD, LPCTSTR); char szClassName[] = "clock"; //ウィンドウクラス int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow)

  • コンパイルエラー: LNK2001

    今、ベクトル計算を簡単にするクラスを作ってみようとしています。 //vector3.h template<class TT> class vector3{ public:   enum{NUM=3};   TT x[NUM];   void set(const TT *vv)void set(const TT *vv){     int i;     for(i=0;i<NUM;i++){       x[i]=vv[i];     }   } }; のように、set関数をクラスの中に書いていると問題無いのですが、以下のように、 //vector3.h template<class TT> class vector3{ public:   enum{NUM=3};   TT x[NUM];   void set(const TT *vv); }; //test.cpp #include"vector3.h" template<class TT> void vector3<TT>::set(const TT *vv){   int i;   for(i=0;i<NUM;i++){     x[i]=vv[i];   } } と、cppファイルの中に書き換えると以下のようにエラーが出るようになります。 error LNK2001: 外部シンボル ""public: void __thiscall vector3<double>::set(double const *)" (?set@?$vector3@N@@QAEXPBN@Z)" は未解決です。 fatal error LNK1120: 外部参照 1 が未解決です。 これはいったい何故なのでしょうか? 使用しているのはVisualC++2008ExpressEditionです 宜しくお願いします。

  • 外部シンボルが未解決

    本に載っていたソースなんですが,外部シンボル 'drand48()' が未解決(C:\NYU.OBJ が参照)というエラーが出てなかなかコンパイルできません。drand48という関数はstdlib.hに含まれていると思うのですが,何故だか分かりません。どなたか分かる方,是非ともお力をお貸しください。 環境はbcc55です。元のソースはC++Builder4で作られたそうです。字数の関係ですべて載せることができませんが,よろしくお願いします! #include <stdio.h> #include <math.h> #include <string.h> #include <locale.h> #include <stdlib.h> #define Iunits 14 #define Hunits 200 #define Ounits 2 #define Rlow -0.30 #define Rhigh 0.30 #define A 1.4 #define B 0.3 #define fout(x) ( 1 / (1 + exp( -(x) ) )) #define urand() ( drand48() * (Rhigh - Rlow) + Rlow ) ~中略 void initialize()/*各ユニットに乱数で重みを振り当てる*/ { int i,j; for (i = 0; i < Hunits; i++){ for (j = 0; j < Iunits; j++){ wih[i][j] = urand(); } shikiih[i] = urand(); } for (i = 0; i < Ounits; i++){ for (j = 0; j < Hunits; j++){ who[i][j] = urand(); } shikiio[i] = urand(); } } ~少略

専門家に質問してみよう