Sign in to follow this  
gash

Issues with stl include and xutility library

Recommended Posts

Hello, I am currently developing a system at my university institute to simplify distributed measurements in electrical networks and have run into some issues. The problem concist of me not being able to add any stl includes to certain files of my project; when I do I get a heap of errors. For example in some certain class-define .cpp files i need to do #include <vector> when i try to add that single line of code to the code below I get the results below from MSVC++ 2003. The error occurs in a diffrent file that otherwise compiles without any problems. Without the stl include all files compile without any errors or warnings. MSVC 2003 output: ---------------------------------------------------------------- c:\system\bin\VSNET\Vc7\include\xutility(168) : error C2766: explicit specialization; 'std::iterator_traits<std::_Bool>' has already been defined c:\system\bin\VSNET\Vc7\include\xutility(335) : error C2084: function 'std::_Scalar_ptr_iterator_tag std::_Ptr_cat(std::_Bool *,std::_Bool *)' already has a body c:\system\bin\VSNET\Vc7\include\xutility(245) : see previous definition of '_Ptr_cat' c:\system\bin\VSNET\Vc7\include\xutility(341) : error C2084: function 'std::_Scalar_ptr_iterator_tag std::_Ptr_cat(const std::_Bool *,std::_Bool *)' already has a body c:\system\bin\VSNET\Vc7\include\xutility(251) : see previous definition of '_Ptr_cat' ---------------------------------------------------------------- Code ----------------------------------------------------------------
#pragma once
#ifndef __ME_UNIT_H__
#define __ME_UNIT_H__

//#include <vector> // <--- When line added problem arises
#include <cvirte.h> // National Instruments CVI runtime env.
#include <userint.h> // NI include from CVI
#include <string.h>
#include <stdlib.h>
#include "me_db.h"
#include "me_logger.h"
#include "me_gpib.h"
#include "nacs.h"
#include "nacs_globals.h"
#include "global_defines.h"

extern class ME_DB *mengine_db;
extern class ME_LOGGER *mengine_log;
extern class ME_GPIB *mengine_gpib;
extern int nacsPanels[NUMBER_OF_PANELS];

//using namespace std; // <- Used if trying to include stl header

class ME_UNIT {
public:
	/* Constructors */
	ME_UNIT ( void );
	ME_UNIT ( const unsigned int type );

	~ME_UNIT ( void );

	/* Public variables */


	/* Public Datastructures */
	struct FrequencyRange{
		double start, stop, steps;
	};

	struct UnitData{
		double pt1pw, pt1att, pt2pw, pt2att, avgFactor;
		int numOfSeg, hwProfile;
		struct FrequencyRange singleSegment;
		struct FrequencyRange frequencySegment[ME_UNIT_8510_MAXLISTENTRIES];
	}data;


	/* Public methods */
	void PopulateControls ( const int panel );
	void RetrieveControlData ( const int panel );
	void WriteData ( const int dataType, const int destination );
	void ReadCalco ( vector<double> &v );
	void WriteCalco ( vector<double> v );

private:
	/* Private Variables */
	unsigned int comType;
	unsigned int unitType;

	/* Private Methods */
	void _wd8510 ( const int dataType );
	void _wdDB ( const int dataType );
	void _wdScreen ( const int dataType );

};
#endif

Platform is MS Windows XP and VC++ .NET 2003. Any suggestions are warmly welcomed. This description may very well be too short. Please don't hesitate to make me clarify some particular part of the problem. Thank you. Best regards, /Gash

Share this post


Link to post
Share on other sites
Try changing the order of includes there is probably something being defined in a non-standard header that is conflicting with other definitions, i usually follow a heuristic (so its just my own rule of thumb) of including my own headers first, then third-party (non-standard headers) second then then last standard headers, if that doesn't work just keep trying different orders e.g.:


#include "me_db.h"
#include "me_logger.h"
#include "me_gpib.h"
#include "nacs.h"
#include "nacs_globals.h"
#include "global_defines.h"

#include <cvirte.h>
#include <userint.h>

#include <cstring>
#include <cstdlib>
#include <vector>


note that c++ standard headers do not have .h & (only in c++) C standard headers also append a c on the front e.g. not math.h but cmath, .h standard headers are deprecated in c++.

note also when you create include guards (or any macro for that matter) make sure that name of the define isn't being used by some other headers that aren't yours because that can also mess you up aswell.

EDIT: quickly glancing at your code, vector is declared & defined in std namespace, so you need to either have a using statement or fully quantify it e.g. std::vector<foo>.

Share this post


Link to post
Share on other sites
Hello snk_kid,

Thank you for your suggestions. I have previously tried the things you mention and to no avail. The perculiar thing is that (as i state in my initial text) the errors do not occur in the same file where the stl inlcude is made (me_unit.h / .cpp) but instead in a different file (nacs_implementor.h / .cpp) wherein i actually make use of my classes. The file in which the error occurs, does however include me_unit.h

In your edit you mention the need for a using statement. I am unsure as to what you mean here. Are you refering to the code that is already in my initial post? At line 21? I have tried rearranging the order of include but so far to no avail. I will keep on trying to shift include orders to see if I can get this segment of code to compile. Thank you for assisting me; if you have more ideas please do not hessitate to post them. :)


Best regards,
/Gash

Share this post


Link to post
Share on other sites
The thing that does confuse me is that _Bool is the C99 boolean type (from <stdbool.h>). Are you mixing C99 and C++ somehow?

Share this post


Link to post
Share on other sites
That's what's been confusing me too for the past three or so hours. :/

As a direct answer to your question on me mixing C99 and C++; the answer is, yes, I am. This is due to the fact that the National Instruments (NI CVI) library is written in C. NI insures me that their lib code is 99.9% compatible with MSVC++ 2k3. This is leading me to think that i have stumbeled onto that last 0.1% which is not. But I doubt it... There has to be a solution to this; it really feels trivial... only i can't seem to figure it out. Atleast not yet. :/

/Gash

Share this post


Link to post
Share on other sites
I've been doing some investigation, the _Bool that vc++ 7.1 is refering to is a typedef for c++ bool defined in the header yvals.h and probably being included by the header utility which xutility includes, vc++ 7.1 doesn't fully support the c99 standard as its a c++ compiler besides so there isn't a stdbool.h header with it.

currently i'm downloading an evaluation version of that library so i might be able to find a solution later on, but in the mean time if you say its a C library then you could try this:


extern "C" {
#include <cvirte.h>
#include <userint.h>
}


EDIT: i thought i might aswell post the statemenet where _Bool is defined in yvals.h


#ifdef __cplusplus
_STD_BEGIN
typedef bool _Bool;
_STD_END
#endif


_STD_BEGIN/_STD_END is a define that just puts thing in namespace std.

Share this post


Link to post
Share on other sites
Hmmm... I actually got this working now... But this was not due to the fact that I actually understood what the error was but rather through trial and error; switching include orders.

Since there are only so many ways to combine the different includes I was determined to find one that actually worked. And now I have one.

But.

Adding an extern statement to the NI includes may very well be the way to go. Atleast for the sake of having "correct" code and not just a setup that "works right now". I do not like numerical solutions to problems which should be solved analytically. I will try your extern statement suggestion now.

Please do tell me if you find any other relevant information later on. Thanks alot!

Best regards,
Gash

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this