Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang++ foo.c doesn't build foo as c++ code #3599

Closed Quuxplusone closed 14 years ago

Quuxplusone commented 14 years ago
Bugzilla Link PR6319
Status RESOLVED DUPLICATE of bug 5803
Importance P normal
Reported by R P Herrold (herrold@owlriver.com)
Reported on 2010-02-16 10:07:51 -0800
Last modified on 2010-02-22 12:49:10 -0800
Version trunk
Hardware PC Linux
CC daniel@zuster.org, dgregor@apple.com, llvm-bugs@lists.llvm.org, nunoplopes@sapo.pt
Fixed by commit(s)
Attachments shim-log.txt (107267 bytes, text/plain)
Blocks
Blocked by
See also
Created attachment 4242
shim-log.txt build log

Using this tarball (containing a material and non-trivial C++ application):

   ftp://ftp.trading-shim.org/pub/local/trading-shim/shim-100205.tgz

and a minimal patch on the Makefile in a CentOS 5 environment, with last night
(15 Feb 2010) SVN pull, I hit the attached (in a moment) blocker, as to how to
specify a namespace.

As I see from the mailing list that adverting C++ support is a goal in short
order, I thought I had better advance my concern

(partial ...)

make -j2 shim
make[1]: Entering directory `/home/herrold/shim/shim-100205'
/usr/bin/clang++ -Wall     -g -I/usr/include/mysql -I/usr/include/c++/4.1.1/ -
I/usr/include/c++/4.1.1/x86_64-redhat-linux  -c -o obj/main.o src/main.c
In file included from src/main.c:8:
In file included from src/main-h.h:11:
In file included from src/glossary.h:11:
In file included from /usr/include/c++/4.1.1/cstdlib:49:
/usr/include/c++/4.1.1/x86_64-redhat-linux/bits/c++config.h:1210:1: error:
unknown type name 'namespace'
namespace __gnu_debug_def { }
^
/usr/include/c++/4.1.1/x86_64-redhat-linux/bits/c++config.h:1210:26: error:
invalid token after top level declarator
namespace __gnu_debug_def { }
                         ^
                         ;
In file included from src/main.c:8:
In file included from src/main-h.h:11:
In file included from src/glossary.h:11:
In file included from /usr/include/c++/4.1.1/cstdlib:50:
/usr/include/c++/4.1.1/cstddef:51:1: error: unknown type name 'namespace'
namespace std
^

... more (complete stdout and stderr) follows in the attached file

May I have a hint,. please?

--------------------------------------------

[herrold@centos-5 shim-100205]$ diff -u Makefile.ORIG Makefile ; rpm -q clang ;
uname -a
--- Makefile.ORIG       2010-02-16 10:55:31.000000000 -0500
+++ Makefile    2010-02-16 10:56:44.000000000 -0500
@@ -30,15 +30,20 @@
 CP       := cp
 RM       := rm -f

-CC       :=        g++
+# CC       :=        g++
 #C       := distcc g++
+CC     :=      /usr/bin/clang++

 JOBS     := -j2
 #OBS     := -j12
 CFLAGS   := -Wall     -g
 #FLAGS   := -Wall -O3 -g
 #FLAGS   := -Wall -O3 -g -std=c++0x
-CPPFLAGS := -I/usr/include/mysql
+# CPPFLAGS := -I/usr/include/mysql
+CPPFLAGS := -I/usr/include/mysql       \
+       -I/usr/include/c++/4.1.1/       \
+       -I/usr/include/c++/4.1.1/x86_64-redhat-linux
+

 SQL      := $(shell mysql_config --libs)
 TWO      := $(filter %/mysql,$(SQL))   \
clang-0.0.20100216.cvs-1orc
Linux centos-5.first.lan 2.6.18-164.11.1.el5xen #1 SMP Wed Jan 20 08:06:04 EST
2010 x86_64 x86_64 x86_64 GNU/Linux
[herrold@centos-5 shim-100205]$
Quuxplusone commented 14 years ago

Attached shim-log.txt (107267 bytes, text/plain): shim-log.txt build log

Quuxplusone commented 14 years ago

Sounds like the code is being built as C. As a wild guess, I'd expect a driver bug.

Quuxplusone commented 14 years ago

Yes, it's a driver bug, here's the command line:

clang++ -Wall -g -I/usr/include/mysql -I/usr/include/c++/4.1.1/ -I/usr/include/c++/4.1.1/x86_64-redhat-linux -c -o obj/main.o src/main.c

The file should be built as c++, even though it ends with ".c".

Quuxplusone commented 14 years ago
Sorry for not giving enough context  -- no plain old C here  ;)

It did not occur to me that a file suffix might be consulted as to what was
happening in a compile

It looks as though I need to sub out that hardcoded 'g++' in the middle as well

For those following along, the Makefile is:

[herrold@centos-5 shim-100205]$ cat Makefile
#  Makefile for the trading shim, an interface to Interactive Brokers' tws api
#  author: Bill Pippin, <pippin@trading-shim.com>, msgs may gate to the list
#  copyright (c) 2005--2007 Trading-shim.com, LLC  Columbus, OH
#  GPL version 3 or later, see COPYING for details

# This makefile belongs in and should be run from the parent directory of
# the directories src, lib, dep, and bin.  The regression test script
# naturally runs the shim and so requires access to a mysql trading shim
# database and a live instance of IB's tws.

# The approach to automatic dependency generation used here is based on p. 153
# of:
#
#     Mecklenburg, "GNU Make", O'Reilly 3rd Ed.
#
# He credits it to to Tom Tromey, as part of his work on FSF's automake tool.

# As of this writing (12.02.08), g++ 4.3.2 at -O3 on Ubuntu 8.04 is
# known to optimize away key ctor parameters during initialization.
# The -O3 level works fine, however, for g++ 4.1.2 on Centos.
# As of 1.02.09, g++ 4.3.2-1 at -O3 on debian testing (lenny) works
# fine, so I'm turning -O3 back on.

#* __________________________________________________________________________ */
#*                                                                            */
#*                                                           Declarations     */
#* __________________________________________________________________________ */

CP       := cp
RM       := rm -f

# CC       :=        g++
#C       := distcc g++
CC      :=      /usr/bin/clang++

JOBS     := -j2
#OBS     := -j12
CFLAGS   := -Wall     -g
#FLAGS   := -Wall -O3 -g
#FLAGS   := -Wall -O3 -g -std=c++0x
# CPPFLAGS := -I/usr/include/mysql
CPPFLAGS := -I/usr/include/mysql        \
        -I/usr/include/c++/4.1.1/       \
        -I/usr/include/c++/4.1.1/x86_64-redhat-linux

SQL      := $(shell mysql_config --libs)
TWO      := $(filter %/mysql,$(SQL))    \
            $(filter %client,$(SQL))
LIB      := $(TWO) -lm

DEP_CHECK = g++ $(CFLAGS) $(CPPFLAGS)

vpath   %.c src lib
vpath   %.h src lib
vpath   %.i src lib
vpath   %.o obj
DPATH    := dep

define you-need-ruby
 (printf "\nRuby must be installed; it's used to generate: %s\n\n" $1 && false)
endef

# sources are grouped by functionality roughly as follows:
# 1st grp: single tree construction, both imperative and constant; and init
# 2nd  "   main: input, process, and output; low-level ops, e.g., operator[]()
# 3rd  "   library component code, application exceptional case handling, and
#          unit testing

SRC:= main.c                            \
      once.c bind.c mode.c time.c       \
      data.c fsms.c syms.c tags.c       \
      type.c sets.c cusp.c link.c       \
      open.c apis.c rule.c late.c       \
      null.c fail.c help.c talk.c       \
                                        \
      shim.c fill.c wait.c read.c       \
      ctor.c proc.c nque.c send.c       \
      tick.c wire.c post.c past.c       \
      echo.c form.c term.c acts.c       \
      name.c leaf.c base.c envs.c       \
      else.c                            \
                                        \
      scan.c hash.c text.c wrap.c       \
      pool.c buds.c inet.c boot.c       \
      math.c dfsa.c

OBJ:= $(SRC:%.c=%.o)

#* __________________________________________________________________________ */
#*                                                                            */
#*                                                                Targets     */
#* __________________________________________________________________________ */

.PHONY: all
all:                    ;       make $(JOBS) shim
shim:   $(OBJ)          ;       (cd obj; $(CXX) -g -o ../shim $(OBJ) $(LIB))
test:   all             ;       exs/test.rb

%.h : %.i               ;       @(bin/$(*F).rb $< > $@) || $(call you-need-
ruby, $(@F))

%.o : %.c
        @$(DEP_CHECK) -M -MF dep/$(subst .o,.d,$@) -MP -MT $@ $<
         $(COMPILE.c) -o obj/$@ $<

sinclude $(SRC:%.c=$(DPATH)/%.d)

.DELETE_ON_ERROR:
debug:                  ;       +make shim 2>&1 | bin/c++.filter | head -16
clean:                  ;       @$(RM) shim obj/*.o; touch */*.i
realclean:              ;       @$(RM) shim obj/*.o; touch */*.i; rm dep/*

[herrold@centos-5 shim-100205]$
Quuxplusone commented 14 years ago

_This bug has been marked as a duplicate of bug 5803_