[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 397
  • Last Modified:

gcc include function error

Hi, I've done a lot of programming but I was never veru good at getting the environment together, I only wanted to code :-/  Right now I have to compile a rather complex application that uses a lot of include <functions> and I am getting "not found" errors.  I figgure that it is because my installation of gcc does not include these functions or plugins.  Is there an easy way to get them install or do I have to compile gcc from scratch?

Is my understanding of this problem correct?  Perhaps this is just a library path problem???

And how about the X11 and Xm includes?  Are they additions to gcc or a separate library?

Thanks, Allan


------------------------------------------CUT HERE------------------------------------
---------------------COMPILATION ERROR---------------------------------------------------
# make
g++ -g -Wall -I../util -c basicSegmentInfo.cc
In file included from basicSegmentInfo.cc:3:
basicSegmentInfo.h:10: error: `string' does not name a type
basicSegmentInfo.h:11: error: `string' does not name a type
------------------------------------------CUT HERE------------------------------------
---------------------CODE HEADER EXAMPLE---------------------------------------------------
#ifndef BASIC_SEGMENT_INFO
#define BASIC_SEGMENT_INFO

#include <string>
#include <vector>

class basicSegmentInfo
{
  public:
        virtual string getName() const = 0;
------------------------------------------CUT HERE------------------------------------
---------------------Makefile---------------------------------------------------
LD = g++
LDFLAGS =
CC = g++

###
#
# compiler flags
#
# delivery:
# CFLAGS = -O2
#
# debug:
# CFLAGS = -g -Wall

UTIL_HEADER_INCLUDE = ../util

CFLAGS = -g -Wall

OBJS = \
 basicSegmentInfo.o\
 orderByDependencies.o

all: ${OBJS}

basicSegmentInfo.o: basicSegmentInfo.h basicSegmentInfo.cc
        ${CC} ${CFLAGS} -I${UTIL_HEADER_INCLUDE} -c basicSegmentInfo.cc

orderByDependencies.o: orderByDependencies.h orderByDependencies.cc
        ${CC} ${CFLAGS} -I${UTIL_HEADER_INCLUDE} -c orderByDependencies.cc

clean:
        rm -rf ${OBJS}
~
~
------------------------------------------CUT HERE------------------------------------
---------------------LIST OF INCLUDES---------------------------------------------------
#include "cds.h"
#include "MenuDataNodes.h"
#include "parser.tab.h"
#include "scanner.h"
#include <stdio.h>
#include <string>
#include <vector>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctype.h>
#include <deque>
#include <Dt/Session.h>
#include <Dt/Wsm.h>
#include <errno.h>
#include <fstream>
#include <grp.h>
#include <io.h>
#include <iostream>
#include <list>
#include <malloc.h>
#include <map>
#include <pwd.h>
#include <queue>
#include <set>
#include <signal.h>
#include <stdarg.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <vector>
#include <wait.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <X11/StringDefs.h>
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <Xm/CascadeB.h>
#include <Xm/DrawingA.h>
#include <Xm/Form.h>
#include <Xm/Frame.h>
#include <Xm/MainW.h>
#include <Xm/MessageB.h>
#include <Xm/MwmUtil.h>
#include <Xm/Protocols.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/ScrolledW.h>
#include <Xm/Separator.h>
#include <Xm/Text.h>
#include <Xm/ToggleB.h>
#include <Xm/Xm.h>
#include <Xm/XmAll.h>
0
huffmana
Asked:
huffmana
  • 3
  • 2
1 Solution
 
AlexFMCommented:
#include <string>
#include <vector>
using namespace std;    // add this line
0
 
AlexFMCommented:
New C++ header files contain all definitions in std namespace. You need to add line
using namespace std;

or use fully names:
virtual std::string getName() const = 0;
0
 
huffmanaAuthor Commented:
WOW like magic :-)  It just compiled.  I'll go through all the code and add this to each file.  Thanks
0
 
huffmanaAuthor Commented:
Hi AlexFM, Most of the programs are compiling now but there is a new error that is showing up, occasionally.  It has to do with namespace so I thought that it may be related to the "using namespace std" problem.

It looks like it is coming from line 14 in less_MenuID.h "  : public binary_function<MenuID, MenuID, bool>" below.  As you can see I've removed "using namespace std" but it still seems to be using std namespace.  I guess that I need to use a full name but I don't know what function it is being called from....

Thanks for your time, I really appreciate your help.  Allan
===========Compile Error===========================

# make
g++ -g -Wall -I../util -c RemoveCycles.cc
In file included from RemoveCycles.h:10,
                 from RemoveCycles.cc:2:
less_MenuID.h:14: error: specialization of `template<class _Tp> struct std::less' in different namespace
/usr/local/lib/gcc/sparc-sun-solaris2.8/3.4.2/../../../../include/c++/3.4.2/bits/stl_function.h:223: error:   from definition of `template<class _Tp> struct std::less'
make: *** [RemoveCycles.o] Error 1
# pwd


===========less_MenuID.h==========================
#ifndef LESS_MENUID_H
#define LESS_MENUID_H

#include <set>
#include <algorithm>
/*using namespace std;    // added Allan */
#include "MenuID.h"

/*
 * class for arbitrary ordering in a set<MenuID>
 */
template <>
struct less<MenuID>
  : public binary_function<MenuID, MenuID, bool>
{
        bool operator()(const MenuID & mid1, const MenuID & mid2) const
        {
                if (mid1.getSegmentName() == mid2.getSegmentName())
                {
                        if (mid1.getType() == mid2.getType())
                        {
                                return (mid1.getMenuName() < mid2.getMenuName());
                        }
                        else
                        {
                                return (mid1.getType() < mid2.getType());
                        }
                }
                else
                {
                        return (mid1.getSegmentName() < mid2.getSegmentName());
                }
        }
};

#endif

===========================================================
0
 
huffmanaAuthor Commented:
The solution ended up being to explicitly opening the std namespace for the entire template!!  


namespace std               // added Allan

{                           // added Allan

template <>

struct less<MenuID>

  : public binary_function<MenuID, MenuID, bool>

{

        bool operator()(const MenuID & mid1, const MenuID & mid2) const

        {

                if (mid1.getSegmentName() == mid2.getSegmentName())

                {

                        if (mid1.getType() == mid2.getType())

                        {

                                return (mid1.getMenuName() < mid2.getMenuName());

                        }

                        else

                        {

                                return (mid1.getType() < mid2.getType());

                        }

                }

                else

                {

                        return (mid1.getSegmentName() < mid2.getSegmentName());

                }

        }

};

 

}                           // added Allan
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now