[cfe-commits] [Patches] Make C++ work on FreeBSD

Ed Schouten ed at 80386.nl
Sun Jun 28 03:32:56 PDT 2009


Hi all,

I'm using the following patch to make the Clang hostinfo work with C++
on FreeBSD. Even though the compilation stage is still forwarded to
`g++', it's useful to get the hostinfo working.

Patch 1:

It looks like Clang doesn't behave like a C++ compiler when called as
`c++' or `g++'. Maybe we should look at the basename or the last bytes
of argv[0], but for now this seems to be good enough:

Index: lib/Driver/Driver.cpp
===================================================================
--- lib/Driver/Driver.cpp	(revision 194810)
+++ lib/Driver/Driver.cpp	(working copy)
@@ -118,6 +118,9 @@
   // driver.
   bool CCCPrintOptions = false, CCCPrintActions = false;
 
+  if (!strcmp(argv[0], "c++") || !strcmp(argv[0], "CC"))
+    CCCIsCXX = true;
+
   const char **Start = argv + 1, **End = argv + argc;
   const char *HostTriple = DefaultHostTriple.c_str();

Patch 2:

Add -lstdc++ and -lm to the linker when building C++, just like we do
with GCC:
 
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp	(revision 194611)
+++ lib/Driver/Tools.cpp	(working copy)
@@ -1858,6 +1858,10 @@
 
   if (!Args.hasArg(options::OPT_nostdlib) &&
       !Args.hasArg(options::OPT_nodefaultlibs)) {
+    if (getToolChain().getHost().getDriver().CCCIsCXX) {
+      CmdArgs.push_back("-lstdc++");
+      CmdArgs.push_back("-lm");
+    }
     // FIXME: For some reason GCC passes -lgcc and -lgcc_s before adding
     // the default system libraries. Just mimic this for now.
     CmdArgs.push_back("-lgcc");

Comments? I can commit it to SVN myself, but as a junior committer I
should get some reviews first.

Yours,
-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20090628/7e82387e/attachment.sig>


More information about the cfe-commits mailing list