Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Problem compiling a C++ file in Linux

I've used some routines from a already made program to make my own; but I get this error (both with gcc and g++) - the errors are in the "< HERE":

In file included from SxP4Test.cpp:8:
stdafx.h:4:9: warning: #pragma once is obsolete
In file included from SxP4Test.cpp:11:
cTle.h:10:9: warning: #pragma once is obsolete
In file included from cTle.h:12,
from SxP4Test.cpp:11:
globals.h:4:9: warning: #pragma once is obsolete
In file included from SxP4Test.cpp:12:
cEci.h:6:9: warning: #pragma once is obsolete
In file included from cEci.h:8,
from SxP4Test.cpp:12:
cVector.h:6:9: warning: #pragma once is obsolete
cVector.h:27:3: warning: no newline at end of file
In file included from cEci.h:9,
from SxP4Test.cpp:12:
cJulian.h:6:9: warning: #pragma once is obsolete
In file included from cEci.h:10,
from SxP4Test.cpp:12:
Coord.h:6:9: warning: #pragma once is obsolete
In file included from SxP4Test.cpp:13:
cOrbit.h:11:9: warning: #pragma once is obsolete
In file included from cOrbit.h:15,
from SxP4Test.cpp:13:
cNoradBase.h:9:9: warning: #pragma once is obsolete
In file included from SxP4Test.cpp:14:
cSite.h:8:9: warning: #pragma once is obsolete
In file included from cSite.h:10,
from SxP4Test.cpp:14:
coord.h:6:9: warning: #pragma once is obsolete
In file included from cSite.h:10,
from SxP4Test.cpp:14:
coord.h:11: error: redefinition of `class cCoordGeo' < HERE
Coord.h:11: error: previous definition of `class cCoordGeo' < HERE
coord.h:26: error: redefinition of `class cCoordTopo' < HERE
Coord.h:26: error: previous definition of `class cCoordTopo' < HERE
In file included from SxP4Test.cpp:14:
cSite.h:38:3: warning: no newline at end of file
coord.h:16: warning: inline function `virtual cCoordGeo::~cCoordGeo()' used but
never defined
coord.h:31: warning: inline function `virtual cCoordTopo::~cCoordTopo()' used
but never defined


The class cCoordGeo and cCoordTopo at coord.h are like this:

class cCoordGeo
{
public:
cCoordGeo();
cCoordGeo(double lat, double lon, double alt) :
m_Lat(lat), m_Lon(lon), m_Alt(alt) {}
virtual ~cCoordGeo() {};

double m_Lat;
double m_Lon;
double m_Alt;
};

and class cCoordTopo:

class cCoordTopo
{
public:
cCoordTopo();
cCoordTopo(double az, double el, double rng, double rate) :
m_Az(az), m_El(el), m_Range(rng), m_RangeRate(rate) {}
virtual ~cCoordTopo() {};

double m_Az;
double m_El;
double m_Range;
double m_RangeRate;
};

What's wrong? - I'm not an expert in C++

This is a little bit urgent ( as always )

Kind regards,

Kepler
[3088 byte] By [kepler] at [2007-11-11 8:32:30]
# 1 Re: Problem compiling a C++ file in Linux
These are warnings, so you can still get a runnable .exe from this file.
There are two problems in the program: your compiler doesn't like the #pragma once directive (which is probably inserted into header files that your project uses). Simply comment this directive out:
//#pragma once

The destructors of your classes look weird. They are defined but contain nothing. In addition, there's a redundant ; after the definition which is probably confusing your compiler. If your destructor does nothing, remove it altogether. It's easier to manage your code when it contains fewer vacuous constructs.
Danny at 2007-11-11 21:01:13 >
# 2 Re: Problem compiling a C++ file in Linux
do you have include guards on those .h files ? I suspect that this is the problem or part of it.
jonnin at 2007-11-11 21:02:19 >
# 3 Re: Problem compiling a C++ file in Linux
I had this same problem, but I was in Windows. To give an example I had three files named employee.h, employee.cpp, and driver.cpp

I put a #includes "employee.h" and #includes "employee.cpp" in the driver.cpp file when all I needed was #includes "employee.h"
alternativecat at 2007-11-11 21:03:17 >