Discussion:
compile .c files as C++?
Jay K
2018-01-25 03:07:34 UTC
Permalink
I have a bunch of C.
I want to move to C++.
I'm using automake.
I don't want to rename any files.
Fortunately I already build libraries and then main separately. That might help, or not matter.
So I want to say:

libfoo_la_CFLAGS += -xc++

and possibly
main_CFLAGS += -xc

Or something higher level and have autoconf
figure it out -- i.e. /TP and /TC for Visual C++.


Makefile.am:337: error: linker flags such as '-xc++' belong in 'libfoo_la_LDFLAGS'


?


- Jay
Thomas Jahns
2018-01-25 11:59:35 UTC
Permalink
Post by Jay K
I have a bunch of C.
I want to move to C++.
I'm using automake.
I don't want to rename any files.
that's unwise and not going to serve you well in the long run. I very much
advise against not renaming files converted from C to C++. While it can be done,
this is very likely to lead to a fragile setup that's gonna encounter lots of
bugs in edge cases. Don't do this, rename your converted files instead.

If you absolutely have to, consider creating dummy C++ files that #include the
corresponding .c file.

C and C++ are sufficiently different languages today that having your tools make
the correct assumptions is crucial. Don't trust random
debuggers/profilers/IDEs/whatever to figure this out.

Regards, Thomas

Loading...