I can't #include

Hey, I just compiled cling on Mac OS X 10.9, but it’s unusable, for some reason #include statements fail.

[code]$ ./bin/cling
In file included from -:1:
In file included from input_line_3:1:
/Users/ninoscript/Documents/Cling/llvm/tools/cling/include/cling/Interpreter/ValuePrinter.h:11:10: fatal error: ‘string’ file not found
#include
^

****************** CLING ******************

  • Type C++ code and press enter to run it *
  •         Type .q to exit             *
    

[cling]$ int i = 1;
[cling]$ #include
In file included from -:1:
input_line_5:1:10: fatal error: ‘vector’ file not found
#include
^
[cling]$ #include
[cling]$ ++i;
[cling]$ #include
In file included from -:1:
input_line_8:1:10: fatal error: ‘iostream’ file not found
#include
^
[cling]$ ++i
[cling]$ i
[1] 24525 segmentation fault ./bin/cling[/code]

Also, even the simplest expressions segfault.

[code]$ ./bin/cling
In file included from -:1:
In file included from input_line_3:1:
/Users/ninoscript/Documents/Cling/llvm/tools/cling/include/cling/Interpreter/ValuePrinter.h:11:10: fatal error: ‘string’ file not found
#include
^

****************** CLING ******************

  • Type C++ code and press enter to run it *
  •         Type .q to exit             *
    

[cling]$ 0
[1] 24773 segmentation fault ./bin/cling[/code]

What can I do to fix it?
I can’t wait to be able to use Cling in my project. :smiley:

Use .I to show current header search paths, and .I /path/to/includeto add new include path.

Doesn’t seem to help.

[code]$ ./cling -Wc++11-extensions -std=c++11
In file included from -:1:
In file included from input_line_3:1:
/Users/ninoscript/Documents/Cling/llvm/tools/cling/include/cling/Interpreter/ValuePrinter.h:11:10: fatal error: ‘string’ file not found
#include
^

****************** CLING ******************

  • Type C++ code and press enter to run it *
  •         Type .q to exit             *
    

[cling]$ .I
-I
/Users/ninoscript/Documents/Cling/llvm/tools/cling/include
-I
/Users/ninoscript/Documents/Cling/build/tools/cling/include
-I
.
-resource-dir
/Users/ninoscript/Documents/Cling/build/lib/clang/3.4
[cling]$ .I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/
[cling]$ #include
In file included from -:1:
input_line_4:1:10: fatal error: ‘string’ file not found
#include
^
[cling]$ .I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1/
[cling]$ #include
[cling]$ //looks like it just didn’t print the error
[cling]$ #include
In file included from -:1:
input_line_7:1:10: fatal error: ‘string’ file not found
#include
^
[cling]$ //there you go
[cling]$ .I
-I
/Users/ninoscript/Documents/Cling/llvm/tools/cling/include
-I
/Users/ninoscript/Documents/Cling/build/tools/cling/include
-I
.
-I
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/
-I
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1/
-resource-dir
/Users/ninoscript/Documents/Cling/build/lib/clang/3.4
[cling]$ 1+1
[1] 28498 segmentation fault ./cling -Wc++11-extensions -std=c++11[/code]

Following the advice on: [url=https://root-forum.cern.ch/t/problems-compiling-on-os-x-10-9/16774/1 compiling on os x 10.9[/url]
Even though I had already installed the Command Line Tools with:

I then tried reinstalling them the same way, but it didn’t work.

I then did the same thing from Xcode, which in the current version just forwards you to the Apple Developer Download website, and tried downloading the .dmg version, and voilà, no header warnings. :smiley:

I now have undefined symbol errors, similar (or maybe the same?) to this issue on Jira.

Here’s a sample session:

[code]$ cling

****************** CLING ******************

  • Type C++ code and press enter to run it *
  •         Type .q to exit             *
    

[cling]$ #include
ExecutionContext: use of undefined symbol ‘_ZNSt8ios_base4InitC1Ev’!
ExecutionContext: use of undefined symbol ‘_ZNSt8ios_base4InitD1Ev’!
ExecutionContext::runStaticInitializersOnce: symbol ‘_ZNSt8ios_base4InitC1Ev’ unresolved while linking static initializer ‘_GLOBAL__I_a2’!
ExecutionContext::runStaticInitializersOnce: symbol ‘_ZNSt8ios_base4InitD1Ev’ unresolved while linking static initializer ‘_GLOBAL__I_a2’!
[cling]$ std
In file included from -:1:
input_line_5:2:2: error: unexpected namespace name ‘std’: expected expression
std
^
[cling]$ std::cout << “arst”;
ExecutionContext: calling unresolved symbol, see previous error message!
ExecutionContext: use of undefined symbol ‘_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc’!
ExecutionContext: use of undefined symbol ‘_ZSt4cout’!
ExecutionContext::executeFunction: symbol ‘_ZSt4cout’ unresolved while linking function ‘_Z15__cling_Un1Qu31v’!
ExecutionContext::executeFunction: symbol ‘_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc’ unresolved while linking function ‘_Z15__cling_Un1Qu31v’!
[cling]$ 1
ExecutionContext: use of undefined symbol ‘_ZN5cling20valuePrinterInternal13flushToStreamERN4llvm11raw_ostreamERKSs’!
ExecutionContext: use of undefined symbol ‘_ZNSsD1Ev’!
ExecutionContext: use of undefined symbol ‘_ZNSsC1ERKSs’!
ExecutionContext: use of undefined symbol ‘_ZNSs6appendEmc’!
ExecutionContext: use of undefined symbol ‘_ZNSs6appendERKSs’!
ExecutionContext::executeFunction: symbol ‘_ZN5cling20valuePrinterInternal13flushToStreamERN4llvm11raw_ostreamERKSs’ unresolved while linking function ‘_Z15__cling_Un1Qu32v’!
ExecutionContext::executeFunction: symbol ‘_ZNSs6appendERKSs’ unresolved while linking function ‘_Z15__cling_Un1Qu32v’!
ExecutionContext::executeFunction: symbol ‘_ZNSs6appendEmc’ unresolved while linking function ‘_Z15__cling_Un1Qu32v’!
ExecutionContext::executeFunction: symbol ‘_ZNSsC1ERKSs’ unresolved while linking function ‘_Z15__cling_Un1Qu32v’!
ExecutionContext::executeFunction: symbol ‘_ZNSsD1Ev’ unresolved while linking function ‘_Z15__cling_Un1Qu32v’!
[cling]$ 1==1
ExecutionContext: use of undefined symbol ‘_ZN5cling20valuePrinterInternal13flushToStreamERN4llvm11raw_ostreamERKSs’!
ExecutionContext: use of undefined symbol ‘_ZNSsD1Ev’!
ExecutionContext::executeFunction: symbol ‘_ZN5cling20valuePrinterInternal13flushToStreamERN4llvm11raw_ostreamERKSs’ unresolved while linking function ‘_Z15__cling_Un1Qu33v’!
ExecutionContext::executeFunction: symbol ‘_ZNSsD1Ev’ unresolved while linking function ‘_Z15__cling_Un1Qu33v’!
[cling]$[/code]

Edit:

I found [url=https://root-forum.cern.ch/t/rootcling-generates-code-for—gnu-cxx-on-osx-with-libc/16683/1 post[/url], apparently it is the same issue.

Edit 2:

cling -stdlib=libstdc++ behaves exactly has just cling, and cling -stdlib=libc++ has the old not found behavior, so I’m compiling again with “-std=c++11 -stdlib=libc++”, let’s see if that does something. I’m just trying out anything that comes to mind, I don’t really have a plan here. :stuck_out_tongue:

Edit 3:

Nope, every combination I can think about gives the same results: not found headers if I use libstdc++, undefined symbols if I use libc++… I’m out of ideas :laughing:

About libc++ and symbol undefined, see here:
[url]Cling -stdlib=libc++ problems

You need to compile your trunk version llvm/clang with ‘-stdlib=libc++’(by clang++), too.

When I compile with libc++ and open cling with libc++, it won’t find C++ header files and most statements segfault, read session I put on my first post, that’s what happens.

I misunderstand before, now I’m clear:
You should use libc++ and solve the header unfound problem:
On my system, .I shows:

-isystem
/usr/include/c++/v1
-isystem
/usr/local/include
-isystem
/usr/lib/clang/3.4/include
-extern-c-isystem
/include
-extern-c-isystem
/usr/include
-I
/var/tmp/portage/dev-lang/cling-9999/work/cling-9999_build/include
-I
.
-resource-dir
/usr/lib/clang/3.4

In your previous result, you do not have a path for libc++ headers.
I rename my libc++ header path to /usr/include/c++/v11, and get the same not found error, I fix it by cling -I /usr/include/c++/v11 -stdlib=libc++
That’s what you need to do.

Thanks, but I tried adding all versions of the headers I have in my computer, both with the .I command and the -I option, and [url=https://root-forum.cern.ch/t/i-cant-include/16840/1 same thing as this log[/url] happens.

Hi,

cling is not yet usable with libc++; we’ll get there in early December.

If you or someone else wants to help: we need to move the standard lib detection routine from here root.cern.ch/gitweb?p=cling.git; … aster#l159

Cheers, Axel.