Mehrfach definierte Symbole



  • Hallo,

    ich bin neu hier, programmiere aber seit ca 8 Jahren. Trotzdem habe ich gerade ein Problem, welches vielleicht Anfänger like ist, dennoch hat es was in sich.

    Ich habe eine stat. lib. erstellt. Diese hat einen Header mit einem template. Dieses template benutzt std::string dadurch muss ich den Header von std::string in diesem Header einbinden.

    Wenn ich nun aber diese lib benutzen will (in einem anderen Projekt) klappt das, oder auch nicht 🙂

    Ich bekomme dann je nachdem eine Fehlermeldung aller "mehrfach definiertes Symbol gefunden".

    Oder aber, wenn ich das std::string include weglasse hat eine undefinierte class.

    Habs mal so:

    namespace{class ifstream;class ofstream;}
    

    probiert, geht aber nicht wegen dem template.

    Hat jemand eine Lösung für mein Problem?

    Das wäre echt super, denn ich verzweifel gerade.

    Der besagte Header:

    // ***************************************************************
    //  XFile   version:  1.0.0   ·  date: 04/14/2008 - init version
    //  -------------------------------------------------------------
    //  XFile   version:  1.1.1   ·  date: 04/17/2008 - upgrade open(...)
    //  -------------------------------------------------------------
    //  XFile   version:  1.2.0   ·  date: 04/21/2008 - change to ifstream and ofstream, because there was trouble with stream
    //  -------------------------------------------------------------
    //  Marcus Finzel
    //  -------------------------------------------------------------
    //  Copyright (C) 2008 - All Rights Reserved
    // ***************************************************************
    // 
    // ***************************************************************
    #ifndef _XFILE_H_798B7265_7020_4955_8673_5EDD1AE39828
    #define _XFILE_H_798B7265_7020_4955_8673_5EDD1AE39828
    #include "jadxtl.h"
    /************************************************************************/
    /* CXFile() flags                                                       */
    /************************************************************************/
    #define XF_BINARY_OUT		0x110001
    #define XF_TEXT_OUT			0x110002
    #define XF_BINARY_IN		0x110003
    #define XF_TEXT_IN			0x110004
    
    #pragma once
    
    namespace{class ifstream;class ofstream;}
    
    _XTL_BEGIN
    
    	typedef unsigned long       DWORD;
    
    	class CXFile
    	{
    	public:
    		// creates a new file 
    		CXFile(void);
    		~CXFile(void);
    		// open a file with strFilename
    		bool open(std::string strFilename, DWORD dwFlag);
    		bool close(void);
    		bool isOpen(void);
    
    		//-----------------------------------------------------------------------------
    		// Name: write()
    		// Desc: obj = the type to write, dwCount = the count of the used type
    		//-----------------------------------------------------------------------------
    		template<typename T> bool write(T& obj, DWORD dwCount);
    
    		//-----------------------------------------------------------------------------
    		// Name: read()
    		// Desc: obj = the type to read, dwCount = the count of the used type
    		//-----------------------------------------------------------------------------
    		template<typename T> bool read(T& obj, DWORD dwCount);
    
    		std::string& GetLastError(void);
    
    	protected:
    	private:
    		bool Compress(void);
    		bool Decompress(void);
    
    		std::string					m_strFilename;		// name of the file, complete
    		std::string					m_strExtension;		// extension of the file
    		std::string					m_strLastError;
    		std::ifstream				m_inStream;			// the inStream
    		std::ofstream				m_outStream;		// the outStream
    		bool						m_bIsOpen;			// is the file open
    		int							m_nOpenMode;		// open mode
    		std::string					m_strHash;			// hash for file
    	};
    
    	template<typename T> bool CXFile::write(T& obj, DWORD dwCount)
    	{
    		if(m_bIsOpen)
    		{
    			m_outStream.write((char*)&obj,sizeof(T)*dwCount);
    
    			if (m_outStream.fail())
    			{
    				m_strLastError = "write fail";
    				return false;
    			}
    
    			return true;
    
    		}
    
    		return false;
    	}
    
    	template<typename T> bool CXFile::read(T& obj, DWORD dwCount)
    	{
    		if(m_bIsOpen)
    		{
    			m_inStream.read((char*)&obj,sizeof(T)*dwCount);
    
    			if (m_inStream.fail())
    			{
    				m_strLastError = "read fail";
    				return false;
    			}
    
    			return true;
    		}
    
    		return false;
    	}
    
    _XTL_END
    #endif
    

    Hier mal die Fehlermeldungen

    msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(void)" (??1?basic_string@DU?basic\_string@DU?char_traits@D@std@@V?allocator@D@2@@std@@QAE@XZ) ist bereits in GameObjectManager.obj definiert. msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: class std::basic\_string,class std::allocator > & \_\_thiscall std::basic\_string,class std::allocator >::operator=(char const *)" (??4?basic_string@DU?chartraits@D@std@@V?char_traits@D@std@@V?allocator@D@2@@std@@QAEAAV01@PBD@Z) ist bereits in GameObjectManager.obj definiert.
    msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(char const *)" (??0?basic_string@DU?basic\_string@DU?char_traits@D@std@@V?allocator@D@2@@std@@QAE@PBD@Z)istbereitsinGameObjectManager.objdefiniert.msvcprtd.lib(MSVCP80D.dll):errorLNK2005:"public:charconst__thiscallstd::basic_string<char,structstd::char_traits<char>,classstd::allocator<char>>::c_str(void)const"(?c_str@?allocator@D@2@@std@@QAE@PBD@Z) ist bereits in GameObjectManager.obj definiert. msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: char const * \_\_thiscall std::basic\_string<char,struct std::char\_traits<char>,class std::allocator<char> >::c\_str(void)const " (?c\_str@?basic_string@DU?chartraits@D@std@@V?char_traits@D@std@@V?allocator@D@2@@std@@QBEPBDXZ) ist bereits in GameObjectManager.obj definiert.
    msvcprtd.lib(MSVCP80D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (??0?basic_string@DU?basic\_string@DU?char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z) ist bereits in GameObjectManager.obj definiert.
    MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: __wcsicmp ist bereits in LIBCMTD.lib(wcsicmp.obj) definiert.
    MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _wcslen ist bereits in LIBCMTD.lib(wcslen.obj) definiert.
    MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _strncpy ist bereits in LIBCMTD.lib(strncpy.obj) definiert.
    MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _calloc ist bereits in LIBCMTD.lib(dbgheap.obj) definiert.
    MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _free ist bereits in LIBCMTD.lib(dbgheap.obj) definiert.
    MSVCRTD.lib(MSVCR80D.dll) : error LNK2005: _malloc ist bereits in LIBCMTD.lib(dbgheap.obj) definiert.
    MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) ist bereits in LIBCMTD.lib(typinfo.obj) definiert.
    MSVCRTD.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) ist bereits in LIBCMTD.lib(typinfo.obj) definiert.
    Bibliothek "..\UnitMaker_debug/Unitmaker.lib" und Objekt "..\UnitMaker_debug/Unitmaker.exp" werden erstellt.

    Gruß
    Marfi



  • Hallo

    Dieser Fehler basiert meistens wenn wenn du falsche Biblitheken zusammen linkst.

    z.B.:

    abxd.lib in der _DEBUG Version compiliert +
    wxyz.lib in der _RELEAS Version compiliert

    Prüfe ob alle deine Biblitheken mit den gelichen Einstellungen
    kompiliert wurden: (_DEBUG,_DLL,_MT,_MFC_VER ...)



  • Müsste in dem Fall Runtime DLL vs. Runtime LIB sein.
    Also entweder alles gegen die DLL Runtime oder alles gegen die LIB Runtime linken, dann passiert sowas nicht.



  • Vielen Dank für die Antwort. Jetzt geht es, aber eine lib musste ich ignorieren.



  • Aha. Auch doof, was? Tip: das ist keine gute Lösung.


Anmelden zum Antworten