Link Error
-
Wie kann es sein dass eine eingebundene CPP Datei dennoch unresolved symbol error für funktionen verursacht?
Es ist keine Lib sondern ein projekt aus mehreren cpp und header dateien.
Es hat die ganze zeit funktioniert und auf einmal bekomme ich für alle funktionen in einer cpp Datei linker error.
-
Hmm, schwer zu sagen. Du hast aber schon immer nur Header-Dateien includiert? (War einen Fehler, den ich mal gemacht hatte früher)
-
linker_ schrieb:
Wie kann es sein dass eine eingebundene CPP Datei dennoch unresolved symbol error für funktionen verursacht?
Funktionsname falsch geschrieben, falsche Anzahl/Typ von Parametern, falsches Semikolon gesetzt. Es gibt sehr viele Möglichkeiten.
-
drakon schrieb:
linker_ schrieb:
Wie kann es sein dass eine eingebundene CPP Datei dennoch unresolved symbol error für funktionen verursacht?
Funktionsname falsch geschrieben, falsche Anzahl/Typ von Parametern, falsches Semikolon gesetzt. Es gibt sehr viele Möglichkeiten.
Habe ich alles überprüft.
Auszug header:
inline double get_max_pan() const; inline double get_min_pan() const; inline double get_max_fov() const; inline double get_min_fov() const; inline double get_max_tilt() const; inline double get_min_tilt() const; inline void set_max_pan(const double new_max); inline void set_min_pan(const double new_min); inline void set_max_fov(const double new_max); inline void set_min_fov(const double new_min); inline void set_max_tilt(const double new_max); inline void set_min_tilt(const double new_min); inline bool valid_max_fov() const; inline bool valid_min_fov() const; inline bool valid_max_pan() const; inline bool valid_min_pan() const; inline bool valid_max_tilt() const; inline bool valid_min_tilt() const; inline bool valid_pan_bound() const; inline bool valid_fov_bound() const; inline bool valid_tilt_bound() const;Genau so sind sie auch in der CPP
Hier die Ausgabe der Fehler
1>canvas.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_pan(void)const " (?get_max_pan@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_pan(void)const " (?get_max_pan@Bound@@QBENXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_pan(void)const " (?get_max_pan@Bound@@QBENXZ) 1>canvas.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_pan(void)const " (?get_min_pan@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_pan(void)const " (?get_min_pan@Bound@@QBENXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_pan(void)const " (?get_min_pan@Bound@@QBENXZ) 1>canvas.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_min_pan(double)" (?set_min_pan@Bound@@QAEXN@Z) 1>frame.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_min_pan(double)" (?set_min_pan@Bound@@QAEXN@Z) 1>interact.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_min_pan(double)" (?set_min_pan@Bound@@QAEXN@Z) 1>canvas.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_max_pan(double)" (?set_max_pan@Bound@@QAEXN@Z) 1>frame.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_max_pan(double)" (?set_max_pan@Bound@@QAEXN@Z) 1>interact.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_max_pan(double)" (?set_max_pan@Bound@@QAEXN@Z) 1>canvas.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_min_tilt(double)" (?set_min_tilt@Bound@@QAEXN@Z) 1>frame.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_min_tilt(double)" (?set_min_tilt@Bound@@QAEXN@Z) 1>interact.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_min_tilt(double)" (?set_min_tilt@Bound@@QAEXN@Z) 1>canvas.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_max_tilt(double)" (?set_max_tilt@Bound@@QAEXN@Z) 1>frame.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_max_tilt(double)" (?set_max_tilt@Bound@@QAEXN@Z) 1>interact.obj : error LNK2001: unresolved external symbol "public: void __thiscall Bound::set_max_tilt(double)" (?set_max_tilt@Bound@@QAEXN@Z) 1>canvas.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_tilt(void)const " (?get_min_tilt@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_tilt(void)const " (?get_min_tilt@Bound@@QBENXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_tilt(void)const " (?get_min_tilt@Bound@@QBENXZ) 1>canvas.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_tilt(void)const " (?get_max_tilt@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_tilt(void)const " (?get_max_tilt@Bound@@QBENXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_tilt(void)const " (?get_max_tilt@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_fov(void)const " (?get_min_fov@Bound@@QBENXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_min_fov(void)const " (?get_min_fov@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_min_fov(void)const " (?valid_min_fov@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_min_fov(void)const " (?valid_min_fov@Bound@@QBE_NXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: double __thiscall Bound::get_max_fov(void)const " (?get_max_fov@Bound@@QBENXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_max_fov(void)const " (?valid_max_fov@Bound@@QBE_NXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_min_pan(void)const " (?valid_min_pan@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_min_pan(void)const " (?valid_min_pan@Bound@@QBE_NXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_max_pan(void)const " (?valid_max_pan@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_max_pan(void)const " (?valid_max_pan@Bound@@QBE_NXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_min_tilt(void)const " (?valid_min_tilt@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_min_tilt(void)const " (?valid_min_tilt@Bound@@QBE_NXZ) 1>frame.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_max_tilt(void)const " (?valid_max_tilt@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_max_tilt(void)const " (?valid_max_tilt@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_tilt_range(double)const " (?valid_tilt_range@Bound@@QBE_NN@Z) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_pan_range(double)const " (?valid_pan_range@Bound@@QBE_NN@Z) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_tilt_bound(void)const " (?valid_tilt_bound@Bound@@QBE_NXZ) 1>interact.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Bound::valid_pan_bound(void)const " (?valid_pan_bound@Bound@@QBE_NXZ)
-
Hier die CPP
inline double Bound::get_max_pan() const { return pan.get_max();} inline double Bound::get_min_pan() const { return pan.get_min();} inline double Bound::get_max_fov() const { return fov.get_max();} inline double Bound::get_min_fov() const { return fov.get_min();} inline double Bound::get_max_tilt() const { return tilt.get_max();} inline double Bound::get_min_tilt() const { return tilt.get_min();} inline bool Bound::valid_max_fov() const { return fov.valid_max();} inline bool Bound::valid_min_fov() const { return fov.valid_min();} inline bool Bound::valid_max_pan() const { return pan.valid_max();} inline bool Bound::valid_min_pan() const { return pan.valid_min();} inline bool Bound::valid_max_tilt() const { return tilt.valid_max();} inline bool Bound::valid_min_tilt() const { return tilt.valid_min();} inline void Bound::set_max_pan(const double new_max) { pan.set_max(new_max); } inline void Bound::set_min_pan(const double new_min) { pan.set_min(new_min); } inline void Bound::set_max_fov(const double new_max) { fov.set_max(new_max); } inline void Bound::set_min_fov(const double new_min) { fov.set_min(new_min); } inline void Bound::set_max_tilt(const double new_max) { tilt.set_max(new_max); } inline void Bound::set_min_tilt(const double new_min) { tilt.set_min(new_min); } inline void Bound::set_pan(const double min,const double max){ pan.set_min(min); pan.set_max(max); } inline void Bound::set_fov(const double min,const double max){ fov.set_min(min); fov.set_max(max); } inline void Bound::set_tilt(const double min,const double max){ tilt.set_min(min); tilt.set_max(max); }
-
Hab mal die bound.cpp,bound.h und eine kleine main hochgeladen.
http://rapidshare.com/files/409873234/link_error_2010_07_29.zipIch wette es ist einfach etwas banales... nur ist es nach einem ganzen tag programmierarbeit nicht mehr möglich die eigenen fehler zu sehen.
-
hier ein komplettes VS2010 projekt.
http://rapidshare.com/files/409875842/link_error_project_2010-07-29.zip
Wäre dankbar wenn jemand drüberschauen könnte bevor ich hier komplett verzweifel.
-
linker_ schrieb:
Hab mal die bound.cpp,bound.h und eine kleine main hochgeladen.
http://rapidshare.com/files/409873234/link_error_2010_07_29.zipIch wette es ist einfach etwas banales... nur ist es nach einem ganzen tag programmierarbeit nicht mehr möglich die eigenen fehler zu sehen.
Sei mal sparsamer mit dem inline. Inline macht eine Funktion nämlich auch static für die Übersetzungseinheit, daher deine Probleme. Außerdem können viele Compiler meistens ganz gut selber entscheiden, welche Funktionen inline sein sollen. Daher ingorieren sie dieses Schlüsselwort mehr oder weniger - bis auf die Tatsache, dass inline Funktionen auch automatisch static sind.
Wenn du den Compiler eher darauf stoßen möchtest, eine Memberfunktion inline zu machen, solltest du kurze Funktionen direkt in der Klassendeklaration definieren. Dann kann das auch ein etwas weniger stark optimierender Compiler (einer der nicht das ganze Programm auf einmal optimiert) inline machen. Und dann stört auch nicht das static. Und du musst übrigens auch nicht inline davor schreiben, falls du dies machst, denn Funktionen die direkt in der Klasse definiert werden, sind automatisch inline.
P.S.: Und man kann es übrigens auch übertreiben mit const-correctness :p
-
SeppJ schrieb:
linker_ schrieb:
Hab mal die bound.cpp,bound.h und eine kleine main hochgeladen.
http://rapidshare.com/files/409873234/link_error_2010_07_29.zipIch wette es ist einfach etwas banales... nur ist es nach einem ganzen tag programmierarbeit nicht mehr möglich die eigenen fehler zu sehen.
Sei mal sparsamer mit dem inline. Inline macht eine Funktion nämlich auch static für die Übersetzungseinheit, daher deine Probleme. Außerdem können viele Compiler meistens ganz gut selber entscheiden, welche Funktionen inline sein sollen. Daher ingorieren sie dieses Schlüsselwort mehr oder weniger - bis auf die Tatsache, dass inline Funktionen auch automatisch static sind.
Volltreffer

Das mit dem static habe ich nicht gewusst...
Ich dachte nur dass er den code an der stelle einsetzt sonst nichts.
-
SeppJ schrieb:
P.S.: Und man kann es übrigens auch übertreiben mit const-correctness :p
Das ist Schulbuchprogrammieren

Schadet es wenn da zuviel const ist? Kostet es performance?Danke übrigens für die guten tipps. hat auf Anhieb geklappt.
-
linker_ schrieb:
SeppJ schrieb:
P.S.: Und man kann es übrigens auch übertreiben mit const-correctness :p
Das ist Schulbuchprogrammieren

Schadet es wenn da zuviel const ist? Kostet es performance?Danke übrigens für die guten tipps. hat auf Anhieb geklappt.
Nein, schaden tut's nicht. Ich fand's nur etwas komisch zu sehen, dass jemand tatsächlich Parameter die by-value übergeben werden als const markiert. Da habe ich erstmal drüber nachdenken müssen, ob da ein tieferer Sinn hinter steckt. Bis ich drauf kam, dass es keinen Sinn macht. Insofern kostet es Entwicklerperformance
.
-
linker_ schrieb:
Schadet es wenn da zuviel const ist?
Ja, es schadet, weil es nichts nützt, aber gleichzeitig irrelevante Informationen in die Schnittstelle bringt. In der Implementierung (Funktionsdefinition) kannst du das machen, es bringt auch da nicht viel, aber im API hat das nichts zu suchen. Oder was soll es den Aufrufer interessieren, ob die Funktion die kopierten Parameter ändert? Ich würde mir
constfür die wichtigen Fälle (in Parameterlisten also Zeiger und Referenzen aufconst-qualfizierte Objekte) reservieren, damit ich eine entsprechende Semantik schneller erkenne.
-
Nur der Interesse halber, das hier wäre sinnvoll?
inline void set_max_pan(const double &new_max); inline void set_min_pan(const double &new_min); inline void set_max_fov(const double &new_max); inline void set_min_fov(const double &new_min); inline void set_max_tilt(const double &new_max); inline void set_min_tilt(const double &new_min);oder bringt byRef mit integralen Typen keinerlei Vorteil?
-
padreigh schrieb:
oder bringt byRef mit integralen Typen keinerlei Vorteil?
double ist kein integraler Typ. Meinst du vielleicht eingebauter Typ?
Ob es bei double einen Vorteil brigt ist nicht einfach zu sagen, bei anderen (kleineren Typen) bringt es keinen wirklichen Vorteil.Folgendes ist jetzt NICHT allgemeingültig, aber auf "normalen" Systemen mit "normalen" Compilern üblich:
Eine Referenz wird intern als Pointer umgesetzt, Größe 4 byte. Die werden in dei Funktion hineinkopiert, an der Stelle also keinerlei Vorteil gegenüber ints und kleinere Datentypen, höchstens gegen long long, double, float, long double (long int ist oft gleich int).
Nach dem Kopieren muss der Pointer intern dann noch dereferenziert werden, was auch wieder etwas kostet.Allgemein ist die Faustregel, dass man eingebaute Typen per value übergibt ud nicht per const Referenz.
-
padreigh schrieb:
Nur der Interesse halber, das hier wäre sinnvoll?
inline void set_max_pan(const double &new_max); inline void set_min_pan(const double &new_min); inline void set_max_fov(const double &new_max); inline void set_min_fov(const double &new_min); inline void set_max_tilt(const double &new_max); inline void set_min_tilt(const double &new_min);oder bringt byRef mit integralen Typen keinerlei Vorteil?
Das bringt bei skalaren Typen nichts.