Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

error: expected unqualified-id before ‘namespace’

8 views
Skip to first unread message

tt

unread,
Jun 2, 2009, 11:28:06 AM6/2/09
to
When I try to compile this file:

namespace test {

class Bob{

};

}

on Ubuntu I get:


error: expected unqualified-id before �namespace�. I have tried to strip
it down as much as possible, Any ideas?

Alf P. Steinbach

unread,
Jun 2, 2009, 11:36:16 AM6/2/09
to
* tt:

See the FAQ on how to post a question about code that doesn't work, then repost.


Cheers & hth.,

- Alf

--
Due to hosting requirements I need visits to <url: http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :-) Just going there is good. Linking
to it is even better! Thanks in advance!

Victor Bazarov

unread,
Jun 2, 2009, 11:39:59 AM6/2/09
to
tt wrote:
> When I try to compile this file:
>
> namespace test {
>
> class Bob{
>
> };
>
> }
>
> on Ubuntu I get:
>
>
> error: expected unqualified-id before �namespace�. I have tried to strip
^^^^^^

> it down as much as possible, Any ideas?

Yes. Compile your code as C++.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

tt

unread,
Jun 2, 2009, 11:51:06 AM6/2/09
to
Victor Bazarov wrote:
> tt wrote:
>> When I try to compile this file:
>>
>> namespace test {
>>
>> class Bob{
>>
>> };
>>
>> }
>>
>> on Ubuntu I get:
>>
>>
>> error: expected unqualified-id before �namespace�. I have tried to strip
> ^^^^^^
>> it down as much as possible, Any ideas?
>
> Yes. Compile your code as C++.
>
> V


I run a Makefile generated with cmake. But if I just do:

g++ test.h -o test

where test.h is the file containing:

namespace test {

class Bob{

};

}

I get no errors. I am not sure what you mean with compiling the code as
C++, since that is what I have done.

Neelesh

unread,
Jun 2, 2009, 11:56:34 AM6/2/09
to
On Jun 2, 8:51 pm, tt <t...@asddd.com> wrote:
> Victor Bazarov wrote:
> > tt wrote:
> >> When I try to compile this file:
>
> >> namespace test {
>
> >>   class Bob{
>
> >> };
>
> >> }
>
> >>  on Ubuntu I get:
>
> >> error: expected unqualified-id before ‘namespace’. I have tried to strip

> >                                  ^^^^^^
> >> it down as much as possible, Any ideas?
>
> > Yes.  Compile your code as C++.
>
> > V
>
> I run a Makefile generated with cmake. But if I just do:
>
> g++ test.h -o test
>
> where test.h is the file containing:
>
> namespace test {
>
>     class Bob{
>
>   };
>
>   }
>
> I get no errors.

Doesn't this indicate that there is some issue with the makefile
rather than with the C++ code?

Victor Bazarov

unread,
Jun 2, 2009, 11:59:11 AM6/2/09
to

Yes, *now* I see that. And, *now* I see that you can't make up your
mind. In your original post you claim that "When I try to compile this
file" (with the same contents), you get errors. Here you say that "if I
just do" (compiling the same file), you "get no errors". So, which is
it? Do you get errors when you compile it, or don't you?

tt

unread,
Jun 2, 2009, 12:07:09 PM6/2/09
to
Neelesh wrote:
> On Jun 2, 8:51 pm, tt <t...@asddd.com> wrote:
>> Victor Bazarov wrote:
>>> tt wrote:
>>>> When I try to compile this file:
>>>> namespace test {
>>>> class Bob{
>>>> };
>>>> }
>>>> on Ubuntu I get:
>>>> error: expected unqualified-id before �namespace�. I have tried to strip

>>> ^^^^^^
>>>> it down as much as possible, Any ideas?
>>> Yes. Compile your code as C++.
>>> V
>> I run a Makefile generated with cmake. But if I just do:
>>
>> g++ test.h -o test
>>
>> where test.h is the file containing:
>>
>> namespace test {
>>
>> class Bob{
>>
>> };
>>
>> }
>>
>> I get no errors.
>
> Doesn't this indicate that there is some issue with the makefile
> rather than with the C++ code?
>
>
>

Yes it does. This is the content from the Makefile that is generated
with cmake:

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.6

# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canoncical targets will work.
.SUFFIXES:

# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list

# Suppress display of executed commands.
$(VERBOSE).SILENT:

# A target that is always out of date.
cmake_force:
.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# The program to use to edit the cache.
CMAKE_EDIT_COMMAND = /usr/bin/cmake-gui

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/tt/spec/RUS

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/tt/spec/RUS/build

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running
CMake cache editor..."
/usr/bin/cmake-gui -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast

# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running
CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast

# The main all target
all: cmake_check_build_system
$(CMAKE_COMMAND) -E cmake_progress_start
/home/tt/spec/RUS/build/CMakeFiles
/home/tt/spec/RUS/build/CMakeFiles/progress.make
$(MAKE) -f CMakeFiles/Makefile2 all
$(CMAKE_COMMAND) -E cmake_progress_start
/home/tt/spec/RUS/build/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean
.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
--check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named RUS

# Build rule for target.
RUS: cmake_check_build_system
$(MAKE) -f CMakeFiles/Makefile2 RUS
.PHONY : RUS

# fast build rule for target.
RUS/fast:
$(MAKE) -f CMakeFiles/RUS.dir/build.make CMakeFiles/RUS.dir/build
.PHONY : RUS/fast

test.o: test.cpp.o
.PHONY : test.o

# target to build an object file
test.cpp.o:
$(MAKE) -f CMakeFiles/RUS.dir/build.make CMakeFiles/RUS.dir/test.cpp.o
.PHONY : test.cpp.o

test.i: test.cpp.i
.PHONY : test.i

# target to preprocess a source file
test.cpp.i:
$(MAKE) -f CMakeFiles/RUS.dir/build.make CMakeFiles/RUS.dir/test.cpp.i
.PHONY : test.cpp.i

test.s: test.cpp.s
.PHONY : test.s

# target to generate assembly for a file
test.cpp.s:
$(MAKE) -f CMakeFiles/RUS.dir/build.make CMakeFiles/RUS.dir/test.cpp.s
.PHONY : test.cpp.s

# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... RUS"
@echo "... edit_cache"
@echo "... rebuild_cache"
@echo "... test.o"
@echo "... test.i"
@echo "... test.s"
.PHONY : help

#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
$(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
--check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

Martijn Mulder

unread,
Jun 2, 2009, 12:23:04 PM6/2/09
to
> Yes it does. This is the content from the Makefile that is generated with
> cmake:
>
> # CMAKE generated file: DO NOT EDIT!

DO NOT use makefiles. They make your life miserable. With a little work you
can use scripts and response files that give you all the flexibility you
need. I don't know for Ubuntu, but on Windows (yes, Microsoft) I can simply
type

C:\cl.exe bob.cpp

and your program compiles without errors


tt

unread,
Jun 2, 2009, 12:30:03 PM6/2/09
to

Thats not really an option I need to build it using cmake. I just don't
understand what it is in the Makefile that gives me the above error. If
I run the same file with:

g++ test.h -o test

or

c++ test.h -o test


there is no error. The Makefile generated with cmake is using c++ and if
I specify g++ it automatically changes to c++. But I don't think thats
the issue.

Paavo Helde

unread,
Jun 2, 2009, 12:59:23 PM6/2/09
to
tt <t...@asddd.com> kirjutas:

> Neelesh wrote:
>> On Jun 2, 8:51 pm, tt <t...@asddd.com> wrote:
>>> Victor Bazarov wrote:
>>>> tt wrote:
>>>>> When I try to compile this file:
>>>>> namespace test {
>>>>> class Bob{
>>>>> };
>>>>> }
>>>>> on Ubuntu I get:

>>>>> error: expected unqualified-id before �namespace�. I have tried to


>>>>> strip
>>>> ^^^^^^
>>>>> it down as much as possible, Any ideas?
>>>> Yes. Compile your code as C++.
>>>> V
>>> I run a Makefile generated with cmake. But if I just do:
>>>
>>> g++ test.h -o test
>>>
>>> where test.h is the file containing:
>>>
>>> namespace test {
>>>
>>> class Bob{
>>>
>>> };
>>>
>>> }
>>>
>>> I get no errors.
>>
>> Doesn't this indicate that there is some issue with the makefile
>> rather than with the C++ code?
>>
>>
>>
>
> Yes it does. This is the content from the Makefile that is generated
> with cmake:

The make system normally outputs the executed commands. You can start by
checking if the command to compile the test.cpp file looks correct and
behaves correctly when launched outside of make.

hth
Paavo

Victor Bazarov

unread,
Jun 2, 2009, 1:36:00 PM6/2/09
to

Do NOT compile *headers*. Compile your .C or .cc or .cpp or .cxx or
.whatever-extension-you're-using-for-the-file-containing-'main' files.

Do NOT post questions about 'make' (gmake, cmake, blahmake) here. We do
not discuss tools here. We discuss *language*.

joshua...@gmail.com

unread,
Jun 2, 2009, 4:48:37 PM6/2/09
to
On Jun 2, 9:23 am, "Martijn Mulder" <i@m> wrote:
> > Yes it does. This is the content from the Makefile that is generated with
> > cmake:
>
> > # CMAKE generated file: DO NOT EDIT!
>
> DO NOT use makefiles. They make your life miserable. With a little work you
> can use scripts and response files that give you all the flexibility you
> need. I don't know for Ubuntu, but on Windows (yes, Microsoft) I can simply
> type

Then you have obviously never worked on any project of a large size.
An incremental build is near required for code which takes hours to
compile. Also, a parallel build system is incredibly vital to make
those hours into (10s of) minutes.

Jeff Schwab

unread,
Jun 2, 2009, 5:55:19 PM6/2/09
to joshua...@gmail.com
joshua...@gmail.com wrote:
> On Jun 2, 9:23 am, "Martijn Mulder" <i@m> wrote:
>>> Yes it does. This is the content from the Makefile that is generated with
>>> cmake:
>>> # CMAKE generated file: DO NOT EDIT!
>> DO NOT use makefiles. They make your life miserable.

Hardly.

> With a little work you
>> can use scripts and response files that give you all the flexibility you
>> need. I don't know for Ubuntu, but on Windows (yes, Microsoft) I can simply
>> type
>
> Then you have obviously never worked on any project of a large size.
> An incremental build is near required for code which takes hours to
> compile. Also, a parallel build system is incredibly vital to make
> those hours into (10s of) minutes.

I'll second that, and add that make-style dependency tracking is not
something you can just script "with a little work."

Zachary Turner

unread,
Jun 2, 2009, 7:02:09 PM6/2/09
to

First of all the command you've just typed above is bogus. You
shouldn't compile .h files, you should compile .cpp files or .c
files. Assuming you have a file named test.cpp then you type

g++ test.cpp -o test

test.cpp would then have a line

#include "test.h"

at the top.

Secondly, assuming the problem really is with CMake and not because
you're trying to compile a header file, then I'm not sure anyone here
can help. I for one know nothing about CMake.

James Kanze

unread,
Jun 3, 2009, 4:17:02 AM6/3/09
to

> C:\cl.exe bob.cpp

I'd be very surprised. You have a very hacked installation if
cl is directly in the root directory of drive C:. If you've
installed the compiler correctly and set up your environment
like Microsoft recommends for command line invocation,
cl bob.cpp
should work, but that's only true for the simplest programs. In
practice, you need a number of additional options to get
anything usable. Something like:
cl -DNOMINMAX -D_CRT_SECURE_NO_DEPRECATE -vmg -GR -Gy -EHs -
Zc:forScope,wchar_t -J -MDd -GS- -Zi -w -D_DEBUG bob.cpp
So you'll want to put it into a batch file or a makefile---all
things considered, the make file is simpler, and does more.

I'm not familiar with cmake or nmake, but gmake---and all of the
usual Unix make's---support macros and generic rules, so you
don't have to write the command out for each file. A typical
gmake file for compiling and linking might be something as
simple as:
sources = bob.cpp
include $(makefileRoot)/binary.mk

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

0 new messages