Linux doesn't like my MSVC8 code

Started by
7 comments, last by T1Oracle 16 years, 9 months ago
I'm trying to move my MSVC8 code over to Code::Blocks on Ubuntu. I was using the gcc compiler but switch to the Intel one when this problem occured, unfortunately that didn't change anything. Here is the code and the complaints from Code::Blocks
#include <boost/thread.hpp>

namespace renwin
{
    // calls glfwInit on construction and glfwTerminate on destruction
    class GLFWInstance
    {
        public:
        GLFWInstance() { glfwInit(); };
        ~GLFWInstance() { glfwTerminate(); };
    };
    class Window // THIS IS THE ERROR
    {
        public:
        // constructs window
        Window(const std::string &appTitle,math::vector2i &resolution,bool isFullscreen);
        // sets the window dimensions
        void SetResolution(math::vector2i &resolution);
        // swaps the display buffers
        void SwapBuffers() const { glfwSwapBuffers(); };
        // issues request to close window
        void Quit() {};
        private:
        boost::mutex mutex; // thread mutex for window // THIS IS THE ERROR TOO
        GLFWInstance glfwIns; // glfw Instance
    };
}
Quote:Code::Blocks /home/bernard/C++ Projects/glfwHello/renwin.h:15: undefined reference to `boost::mutex::~mutex()' /home/bernard/C++ Projects/glfwHello/renwin.h:15: undefined reference to `boost::mutex::~mutex()' /home/bernard/C++ Projects/glfwHello/rewnwin.cpp:15: undefined reference to `boost::mutex::mutex()' /home/bernard/C++ Projects/glfwHello/rewnwin.cpp:20: undefined reference to `boost::mutex::~mutex()' /home/bernard/C++ Projects/glfwHello/rewnwin.cpp:15: undefined reference to `boost::mutex::mutex()' /home/bernard/C++ Projects/glfwHello/rewnwin.cpp:20: undefined reference to `boost::mutex::~mutex()'
// reads count objects into output iterator dest
template <typename Stream,typename OutputIterator,typename ValueT>
void Read(Stream &s,OutputIterator &dest, boost::uint32_t count)
{
	std::iterator_traits<OutputIterator>::value_type temp; // THIS IS THE ERROR
	while (count--)
	{
		Read(s,temp);
		*dest++=temp;
	}
}
Quote:Code::Blocks /home/bernard/C++ Projects/glfwHello/iolib.h:13: error: expected `;' before ‘temp’ /home/bernard/C++ Projects/glfwHello/iolib.h:16: error: ‘temp’ was not declared in this
namespace renwin
{
    lg::Log<std::fstream> Log()
    {
        boost::shared_ptr<std::fstream> pLogFile(new std::fstream("log.txt",std::ios::out|std::ios::app));
        return lg::Log<std::fstream>(pLogFile,"PakFile");
    }
}

using namespace renwin;

Window::Window(const std::string &appTitle,math::vector2i &resolution,bool isFullscreen)
{
    if( !glfwOpenWindow( resolution[math::X], resolution[math::Y], 0, 0, 0, 0, 16, 0, (isFullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) ) );
       throw ex::open_failed_error(Log(),std::string("Failed to open window: ")+appTitle); // THIS IS THE ERROR
    glfwSetWindowTitle(appTitle.c_str());
}
The log header is
#pragma once

namespace lg
{
	class endl
	{
	};

	template <typename Stream>
	Stream& operator << (Stream& os,const endl& end) { os<<")>-"<<std::endl;return os; };
	template <typename Stream>
	class Log
	{
	public:
		Log(boost::shared_ptr<Stream> pOutputStream,const std::string ownerLabel) : ownerLbl(ownerLabel), pLS(pOutputStream) { };
		~Log() { pLS->flush(); }; // writes output to log

		// returns stream for logging errors
		Stream &Error(void) { (*pLS)<<"-<("<<ownerLbl<<"-Error: ";pLS->flush();return *pLS; };
		// returns stream for logging warnings
		Stream &Warning(void) { (*pLS)<<"-<("<<ownerLbl<<"-Warning: ";pLS->flush();return *pLS; };
		// returns stream for logging messages
		Stream &Message(void) { (*pLS)<<"-<("<<ownerLbl<<"-Message: ";pLS->flush();return *pLS; };

	private:
		boost::shared_ptr<Stream> pLS; // pointer to stream for log output
		std::string ownerLbl; // string label for owner of log
	};
};
Quote:Code::Blocks /home/bernard/C++ Projects/glfwHello/rewnwin.cpp:18: error: no matching function for call to ‘ex::open_failed_error::open_failed_error(lg::Log<std::basic_fstream<char, std::char_traits<char> > >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >)’ /home/bernard/C++ Projects/glfwHello/exceptions.h:153: note: candidates are: ex::open_failed_error::open_failed_error(LOG&, std::string) [with LOG = lg::Log<std::basic_fstream<char, std::char_traits<char> > >] /home/bernard/C++ Projects/glfwHello/exceptions.h:150: note: ex::open_failed_error::open_failed_error() /home/bernard/C++ Projects/glfwHello/exceptions.h:148: note: ex::open_failed_error::open_failed_error(const ex::open_failed_error&) /home/bernard/C++ Projects/glfwHello/rewnwin.cpp:9: instantiated from here /home/bernard/C++ Projects/glfwHello/log.h:27: warning: ‘lg::Log<std::basic_fstream<char, std::char_traits<char> > >::ownerLbl’ will be initialized after /home/bernard/C++ Projects/glfwHello/log.h:26: warning: ‘boost::shared_ptr<std::basic_fstream<char, std::char_traits<char> > > lg::Log<std::basic_fstream<char, std::char_traits<char> > >::pLS’ /home/bernard/C++ Projects/glfwHello/log.h:15: warning: when initialized here
Any help would be much appreciated.
Programming since 1995.
Advertisement
Concerning your first error: does the mutex library require linking with something?

Concerning your second error: when using the :: operator to resolve the name of a type from an entity which depends on a type parameter of your template (typically, the Container<T>::iterator or T::subtype cases), you must indicate that you are looking for a type by adding the typename keyword.
Thanks man, that just leaves the problem with the exception class. I didn't bother with the looking for a library to link since it looked like the error was during the compiling stage. I guess I'm too spoiled by MSVC8 which separates the link stage from the compiling stage.
*edit*
class open_failed_error : public write_error{public:	open_failed_error throw() {};	virtual ~read_only_error() throw() {};	template<typename LOG>	open_failed_error &log,std::string msg) { Log(*this,log,msg); };	template<typename LOG,typename T>	open_failed_error &log,T &t,std::string msg) { Log(*this,log,t,msg); };	virtual const char *ExName() { return "write attempt to read only data"; }; // name of exception};

That's how my exception classes are defined.
Programming since 1995.
The third one looks like you're missing an #include <string>, bug I'm not certain.
I have a stdafx.h header that it is included in all .cpp files. It includes the following:
Quote:
#include <GL/glfw.h>
#include <iostream>
#include <ios>
#include <istream>
#include <ostream>
#include <algorithm>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <iterator>
#include <exception>
#include <boost/cstdint.hpp>
#include <boost/thread.hpp>
#include <boost/iostreams/stream.hpp>
#include <boost/iostreams/categories.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/utility.hpp>
#include <boost/smart_ptr.hpp>
#include <boost/foreach.hpp>
#include <boost/range.hpp>
#include <cml/cml.h>
#include "exceptions.h"
#include "myMath.h"
#include "iolib.h"
#include "log.h"


I'm still not sure how to make stdafx.h as my precompiled header just as I have it in MSVC8. I'll have to do more reading.
Programming since 1995.
Is you're open_file_error a copy 'n' paste to the forum? If so you've managed to miss some bits:

//open_failed_error throw() {};open_failed_error() throw() {};//open_failed_error &log,std::string msg) { Log(*this,log,msg); };open_failed_error(const LOG &log,std::string msg) { Log(*this,log,msg); };//open_failed_error &log,T &t,std::string msg) { Log(*this,log,t,msg); };open_failed_error(const LOG &log,T &t,std::string msg) { Log(*this,log,t,msg); };
"Voilà! In view, a humble vaudevillian veteran, cast vicariously as both victim and villain by the vicissitudes of Fate. This visage, no mere veneer of vanity, is a vestige of the vox populi, now vacant, vanished. However, this valorous visitation of a bygone vexation stands vivified, and has vowed to vanquish these venal and virulent vermin vanguarding vice and vouchsafing the violently vicious and voracious violation of volition. The only verdict is vengeance; a vendetta held as a votive, not in vain, for the value and veracity of such shall one day vindicate the vigilant and the virtuous. Verily, this vichyssoise of verbiage veers most verbose, so let me simply add that it's my very good honor to meet you and you may call me V.".....V
Quote:Original post by joanusdmentia
Is you're open_file_error a copy 'n' paste to the forum? If so you've managed to miss some bits:

*** Source Snippet Removed ***


Yea I did, I was kind of careless with that copy. It doesn't matter now though, I refactored my logging and exception system and removed all of the templates. Now it compiles just fine and it uses boost iostreams to allow the log to operate as an output stream (which is better than my prior method). It also spits out xml now too, although it doesn't have a body tag but that can be added as a post processing step when the log file needs to be examined.
Programming since 1995.
Quote:Original post by T1OracleI guess I'm too spoiled by MSVC8 which separates the link stage from the compiling stage.

GCC does that too (and the boost::mutex errors you posted are linker errors)
Quote:Original post by Spoonbender
Quote:Original post by T1OracleI guess I'm too spoiled by MSVC8 which separates the link stage from the compiling stage.

GCC does that too (and the boost::mutex errors you posted are linker errors)


I meant that the Code::Blocks output did not show that the error is from the linking stage and not the compiling staged.
Programming since 1995.

This topic is closed to new replies.

Advertisement