2017-07-20 5 views
-1

私は数日間、MSVS 15の概念証明テストプロジェクトでいくつかの問題を解決しようとしていました。私が見ている問題は、解決できない名前空間にいくつかの機能があることです。適切にコード化されたDebugedネームスペースで未解決の関数

私が自分のコードに問題がないので、自動検索SOリストのトップ質問は一切役に立たなかった。 Googleはまた、何か役に立つものを出せなかった。私の問題の一部ではない他のSOの質問のようなコード化された同じ問題だけです。

私が知る限り、名前空間コードは正しいですが、リンカーはまだ関数定義を見つけていません。名前空間のすべての関数が未解決のリンカーエラーを取得しています。

util.h

#include <string> 
#include <vector> 
#include <map> 
#include "logging.h" 
#include <random> 

using std::string; 
using std::vector; 
using std::map; 
using std::pair; 
using std::to_string; 

namespace Util { 
    //Utility Function Predefs 
    map<string, float> fillMap(map<string, float>argMap); 
    map<string, int> fillMap(map<string, int>argMap); 

    void createBInfo(string errType, string fl, string lnNm, string dt, string tm, string errCode, string errMsg, string fPath); 
    float calcPop(int pERand, int pSRand, int popRand1, int popRand2, int popRand3); 
    int getDefenses(int rand, float eks); 
    int getShields(int rand, float eks); 
    int getIRand(int low, int high); 
    float getFRand(float low, float high); 
    int calcXP(int base, int level, float factor); 

    //Utility Members 
    extern map<string, float>::iterator itf1; 
    extern map<string, int>::iterator iti1; 
    extern map<string, float>rtnFMap; 
    extern map<string, int>rtnIMap; 

    extern int i1; 
    extern int nOfDef; 
    extern int nOfShd; 

    //For Debug 
    extern string file, bLocale, bTDate; 
} 

util.cppを

#include "util.h" 
#include <math.h> 
#include "consts.h" 
#include "logging.h" 

Logging l_u; 
std::random_device rd; 
std::mt19937 gen(rd()); 

namespace Util { 
    //Name: fillMap 
    //Description: Fill a map reference passed through with the contents of another map from dataSystem 
    /*Arguments: 
    *argMap1 - This map contains a map of settings loaded passed in from another function 
    */ 
    map<string, float> fillMap(map<string, float>argMap1) { 
     for (itf1 = argMap1.begin(); itf1 != argMap1.end(); itf1++) { 
      rtnFMap.insert(pair<string, float>(itf1->first, itf1->second)); 
     } 

     return rtnFMap; 
    } 

    //Name: fillMap 
    //Description: Fill a map reference passed through with the contents of another map from dataSystem; int value override 
    /*Arguments: 
    *argMap1 - This map contains a map of settings loaded passed in from another function 
    */ 
    map<string, int> fillMap(map<string, int>argMap1) { 
     for (iti1 = argMap1.begin(); iti1 != argMap1.end(); iti1++) { 
      rtnIMap.insert(pair<string, int>(iti1->first, iti1->second)); 
     } 

     return rtnIMap; 
    } 


    void createBInfo(string errType, string fl, string lnNm, string dt, string tm, string errCode, string errMsg, string fPath) { 
     file = fl; 
     bLocale = "File: " + file + " Line: " + lnNm; 
     bTDate = dt + " " + tm; 

     l_u.createLReport(errType, errCode, errMsg, bLocale, bTDate, fPath); 
    } 

    int calcXP(int base, int level, float factor) { 
     return trunc(base * (pow(level, factor))); 
    } 

    int getDefenses(int rand, float eks) { 
     if ((eks > 0.0f) && (eks < 1.0f)) { //Type 0 Planet 
      if ((rand >= 1) && (rand <= 35)) { nOfDef = 0; } //36% chance for 0 defenses   
      else if ((rand >= 36) && (rand <= 60)) { nOfDef = 1; } //25% chance for 1 defense 
      else if ((rand >= 61) && (rand <= 78)) { nOfDef = 2; } //18% chance for 2 defenses 
      else if ((rand >= 79) && (rand <= 87)) { nOfDef = 3; } //7% chance for 3 defenses 
      else if ((rand >= 88) && (rand <= 94)) { nOfDef = 4; } //7% chance for 4 defenses 
      else if ((rand >= 95) && (rand <= 98)) { nOfDef = 5; } //4% chance for 5 defenses 
      else if (rand >= 99) { nOfDef = 6; } //2% Chance for 6 defenses 
     } 
     else if ((eks >= 1.0f) && (eks < 2.0f)) { //Type 1 Planet 
      if ((rand >= 1) && (rand <= 28)) { nOfDef = 0; } //29% chance for 0 defenses   
      else if ((rand >= 29) && (rand <= 55)) { nOfDef = 1; } //28% chance for 1 defense 
      else if ((rand >= 56) && (rand <= 71)) { nOfDef = 2; } //16% chance for 2 defenses 
      else if ((rand >= 72) && (rand <= 82)) { nOfDef = 3; } //11% chance for 3 defenses 
      else if ((rand >= 83) && (rand <= 90)) { nOfDef = 4; } //8% chance for 4 defenses 
      else if ((rand >= 91) && (rand <= 96)) { nOfDef = 5; } //7% chance for 5 defenses 
      else if (rand >= 97) { nOfDef = 6; } //4% Chance for 6 defenses 
     } 
     else if ((eks >= 2.0f) && (eks < 3.0f)) { //Type 2 Planet 
      if ((rand >= 1) && (rand <= 28)) { nOfDef = 0; } //29% chance for 0 defenses   
      else if ((rand >= 29) && (rand <= 56)) { nOfDef = 1; } //28% chance for 1 defense 
      else if ((rand >= 57) && (rand <= 70)) { nOfDef = 2; } //14% chance for 2 defenses 
      else if ((rand >= 71) && (rand <= 82)) { nOfDef = 3; } //12% chance for 3 defenses 
      else if ((rand >= 83) && (rand <= 91)) { nOfDef = 4; } //9% chance for 4 defenses 
      else if ((rand >= 92) && (rand <= 96)) { nOfDef = 5; } //5% chance for 5 defenses 
      else if (rand >= 97) { nOfDef = 6; } //4% Chance for 6 defenses 
     } 
     else if ((eks >= 3.0f) && (eks < 4.0f)) { //Type 3 Planet 
      if ((rand >= 1) && (rand <= 20)) { nOfDef = 0; } //21% chance for 0 defenses   
      else if ((rand >= 21) && (rand <= 46)) { nOfDef = 1; } //26% chance for 1 defense 
      else if ((rand >= 47) && (rand <= 68)) { nOfDef = 2; } //19% chance for 2 defenses 
      else if ((rand >= 69) && (rand <= 80)) { nOfDef = 3; } //13% chance for 3 defenses 
      else if ((rand >= 81) && (rand <= 89)) { nOfDef = 4; } //9% chance for 4 defenses 
      else if ((rand >= 90) && (rand <= 95)) { nOfDef = 5; } //6% chance for 5 defenses 
      else if (rand >= 96) { nOfDef = 6; } //3% Chance for 6 defenses 
     } 
     else if ((eks >= 4.0f) && (eks < 5.0f)) { //Type 4 Planet 
      if (rand >= 1 && rand <= 18) { nOfDef = 0; } //19% chance for 0 defenses   
      else if (rand >= 19 && rand <= 35) { nOfDef = 1; } //15% chance for 1 defense 
      else if (rand >= 36 && rand <= 55) { nOfDef = 2; } //20% chance for 2 defenses 
      else if (rand >= 56 && rand <= 68) { nOfDef = 3; } //13% chance for 3 defenses 
      else if (rand >= 69 && rand <= 80) { nOfDef = 4; } //12% chance for 4 defenses 
      else if (rand >= 81 && rand <= 89) { nOfDef = 5; } //9% chance for 5 defenses 
      else if (rand >= 90 && rand <= 95) { nOfDef = 6; } //6% Chance for 6 defenses 
      else if (rand >= 96) { nOfDef = 7; } //5% chance for 7 defenses 
     } 
     else if (eks >= 5.0f) { //Type 5 Planet 
      if (rand >= 1 && rand <= 12) { nOfDef = 0; } //13% chance for 0 defenses   
      else if (rand >= 13 && rand <= 28) { nOfDef = 1; } //16% chance for 1 defense 
      else if (rand >= 29 && rand <= 48) { nOfDef = 2; } //20% chance for 2 defenses 
      else if (rand >= 49 && rand <= 62) { nOfDef = 3; } //14% chance for 3 defenses 
      else if (rand >= 63 && rand <= 74) { nOfDef = 4; } //12% chance for 4 defenses 
      else if (rand >= 75 && rand <= 85) { nOfDef = 5; } //11% chance for 5 defenses 
      else if (rand >= 86 && rand <= 92) { nOfDef = 6; } //9% Chance for 6 defenses 
      else if (rand >= 93 && rand <= 97) { nOfDef = 7; } //5% Chance for 7 defenses 
      else if (rand >= 98) { nOfDef = 8; } //3% chance for 8 defenses 
     } 

     return nOfDef; 
    } 

    int getShields(int rand, float eks) { 
     if ((eks > 0.0f) && (eks < 1.0f)) { //Type 0 Planet 
      if ((rand >= 1) && (rand <= 60)) { nOfShd = 0; } //61% chance for 0 shields 
      else if ((rand >= 61) && (rand <= 86)) { nOfShd = 1; } //26% chance for 1 shields 
      else if (rand >= 86) { nOfShd = 2; } //17% chance for 2 shields 
     } 
     else if ((eks >= 1.0f) && (eks < 2.0f)) { //Type 1 Planet 
      if ((rand >= 1) && (rand <= 52)) { nOfShd = 0; } //53% chance for 0 shields 
      else if ((rand >= 53) && (rand <= 84)) { nOfShd = 1; } //22% chance for 1 shields 
      else if (rand >= 85) { nOfShd = 2; } //15% chance for 2 shields 
     } 
     else if ((eks >= 2.0f) && (eks < 3.0f)) { //Type 2 Planet 
      if ((rand >= 1) && (rand <= 35)) { nOfShd = 0; } //36% chance for 0 shields 
      else if ((rand >= 36) && (rand <= 68)) { nOfShd = 1; } //33% chance for 1 shields 
      else if ((rand >= 68) && (rand <= 87)) { nOfShd = 2; } //18% chance for 2 shields 
      else if (rand >= 88) { nOfShd = 3; } //13% chance for 3 shields 
     } 
     else if ((eks >= 3.0f) && (eks < 4.0f)) { //Type 3 Planet 
      if ((rand >= 1) && (rand <= 27)) { nOfShd = 0; } //28% chance for 0 shields 
      else if ((rand >= 28) && (rand <= 64)) { nOfShd = 1; } //27% chance for 1 shields 
      else if ((rand >= 65) && (rand <= 84)) { nOfShd = 2; } //21% chance for 2 shields 
      else if (rand >= 85) { nOfShd = 3; } //16% chance for 3 shields 
     } 
     else if ((eks >= 4.0f) && (eks < 5.0f)) { //Type 4 Planet 
      if ((rand >= 1) && (rand <= 20)) { nOfShd = 0; } //21% chance for 0 shields 
      else if ((rand >= 21) && (rand <= 48)) { nOfShd = 1; } //28% chance for 1 shields 
      else if ((rand >= 49) && (rand <= 74)) { nOfShd = 2; } //26% chance for 2 shields 
      else if ((rand >= 75) && (rand <= 88)) { nOfShd = 3; } //14% chance for 3 shields 
      else if (rand >= 89) { nOfShd = 4; } //12% chance for 4 shields 
     } 
     else if (eks >= 5.0f) { //Type 5 Planet 
      if ((rand >= 1) && (rand <= 18)) { nOfShd = 0; } //19% chance for 0 shields 
      else if ((rand >= 19) && (rand <= 36)) { nOfShd = 1; } //18% chance for 1 shields 
      else if ((rand >= 37) && (rand <= 65)) { nOfShd = 2; } //29% chance for 2 shields 
      else if ((rand >= 66) && (rand <= 84)) { nOfShd = 3; } //19% chance for 3 shields 
      else if (rand >= 85) { nOfShd = 4; } //16% chance for 4 shields 
     } 

     return nOfShd; 
    } 

    float calcPop(int pERand, int pSRand, int popRand1, int popRand2, int popRand3) { 
     return ((((((8000 * popRand1) * popRand2) * pERand) * pSRand) * popRand3)/6); 
    } 

    int getIRand(int low, int high) { 
     return std::uniform_int_distribution<>{low, high}(gen); 
    } 

    float getFRand(float low, float high) { 
     return std::uniform_real_distribution<float> {low, high}(gen); 
    } 
} 

エラーの原因となって、名前空間の関数呼び出しの抜粋例:

#include <iostream> 
#include <stdlib.h> 
#include "planet.h" 
#include <Windows.h> 
#include <sstream> 
#include <cmath> 
#include "util.h" 
#include "consts.h" 

... 

void Planet::createBelts() { 
    beltRand = Util::getIRand(0, 10); 

    if (beltRand != 0) { 
     for (i = 1; i <= beltRand; i++) { 
      ramount = Util::getIRand(3, 15); //External value tag: int range 
      size = ((ramount * Util::getFRand(1000.0f, 50000.00f) * 46)/2); //External value tag: float range 
      name = plName + " Asteroid Belt " + rNumerals[i - 1]; 

      addBelt(name, size, ramount, false); 
     } 
    } 
} 

... 

アップデート:ここで

がありますリンカーのいくつかが間違っています私は見ているors。

unresolved external symbol "float __cdecl Util::calcPop(int,int,int,int,int)" ([email protected]@@[email protected]) referenced in function "public: void __thiscall planetarySystem::generatePlanets(void)" ([email protected]@@QAEXXZ)

unresolved external symbol "float __cdecl Util::getFRand(float,float)" ([email protected]@@[email protected])

unresolved external symbol "float __cdecl Util::getFRand(float,float)" ([email protected]@@[email protected]) unresolved external symbol "float __cdecl Util::getFRand(float,float)" ([email protected]@@[email protected])

unresolved external symbol "int __cdecl Util::getDefenses(int,float)" ([email protected]@@[email protected])

+0

exeまたはdllがリンクされていると、リンクエラーが表示されます。これはコンパイルが完了した後に起こります(このプロジェクトでは)、コンパイルエラーが表示されリンクエラーが発生することがあります。 ** Output **ログは、検出されたすべてのエラーの完全なリストを提供します。 (これは "未解決のextern symbol errorsは他のエラーを吹っ飛ばすかもしれない"と言われていますが、間違ったことを理解しているかもしれません。) – Scheff

+2

考えられる原因が多すぎます。あまりにも多くのコード。 1つのエラーに焦点を当て、そのエラーを再現する[mcve]にコードを減らすことをお勧めします。 – user4581301

+0

通常の方法を使用します:最初のエラーを解決し、すべてが消えるまで次のエラーに進みます。 (見ていないと、問題は変数であり、関数ではないと思います) – molbdnilo

答えて

0

4日後、最終的に名前空間の問題に関する問題が見つかりました。プロジェクトが存在するソリューションファイルはMSVS 2012で生成され、以前はMSVS 2015に変換されました。私はなぜこれが問題なのか分かりませんが、2015年に新しいプロジェクトを作成してコードファイルを投げたとき、私のネームスペース未解決のリンカエラーが修正されました。

関連する問題