C Properly setting up C/C++ headers

I am trying to setup my headers for mainly C development but I will also need to link in some C++ code as well. It's been a while and I totally made a mess of things;

I will be using some of the clang tools I wrote a simple test program that runs into linker errors.

Code:
clang++ -I/usr/local/llvm40/include/clang test.cpp

returns this error:

In file included from test.cpp:4:
Code:
/usr/local/llvm40/include/clang-c/Index.h:21:10: fatal error: 
      'clang-c/Platform.h' file not found
#include "clang-c/Platform.h"
         ^~~~~~~~~~~~~~~~~~~~
1 error generated

I am using tcsh as a shell; .cshrc env variables look like this so far
Code:
setenv    LDFLAGS                   "-L/usr/local/lib"
setenv    CPPFLAGS                  "-I/usr/local/include -I/usr/local/llvm40/include"
setenv    CC                          clang
setenv    CXX                       clang++

I know that I should be able to add my lib and include directories to my .cshrc file so I do not have to manually pass all those arguments to clang.

How do I properly setup my header search path?
 
If you have all the source code (for the C and the C++ parts), the easiest thing to do is: Compile everything with the C++ compiler, simply treating your C code as "C++ without classes". There are some subtle differences between C and C++, but in practice, they are unlikely to matter.

Having done that, things should just work. I think you are making it way too complicated:
  • When you say "clang++ -I/usr/local/llvm40/include/clang test.cpp", why are you adding the include path? Just say "clang++ test.cpp", and it will compile your test program, link it (you didn't specify the "-c" option), and put the executable into a.out. Why do you even need the -I option?
  • Where are you going to put your include files? If your project is small (for example a dozen source files), then just use a single directory, done, no flags needed.
  • For standard (language and operating system) include files, you do not need to specify the search path. They are found automatically. Messing with the include path like you did with your -I flag will only screw things up.
  • Why are you adding the "-L /usr/local/lib" flag? Are you storing your own source libraries there? Why not in a project directory? Development of one particular program should have no business changing the state of the whole operating system installation.
  • In general, unless you are doing something very unusual, clang (or gcc for that matter) will not need any environment variable to be set. The normal way to influence their behavior is via command line flags. In particular, if the source code and libraries are in a single directory, it doesn't need any -I or -L flags; if you break your project into a small directory tree, it only needs a few -I and -L flags that point to places within the tree.
  • Why are you doing your setup using environment variables that are set in .cshrc? The same user account can be used for developing different projects, which may need different settings.
  • Why are you not using make? Writing a makefile for a simple project is very easy. And the makefile is the easy and traditional way to store special configurations, such as compiler flags. If I had a penny for each time I've added -Wall to CXXFLAGS in my live, I would be slightly less poor.
 
If you have all the source code (for the C and the C++ parts), the easiest thing to do is: Compile everything with the C++ compiler, simply treating your C code as "C++ without classes". There are some subtle differences between C and C++, but in practice, they are unlikely to matter.

Having done that, things should just work. I think you are making it way too complicated:
  • When you say "clang++ -I/usr/local/llvm40/include/clang test.cpp", why are you adding the include path? Just say "clang++ test.cpp", and it will compile your test program, link it (you didn't specify the "-c" option), and put the executable into a.out. Why do you even need the -I option?
  • Where are you going to put your include files? If your project is small (for example a dozen source files), then just use a single directory, done, no flags needed.
  • For standard (language and operating system) include files, you do not need to specify the search path. They are found automatically. Messing with the include path like you did with your -I flag will only screw things up.
  • Why are you adding the "-L /usr/local/lib" flag? Are you storing your own source libraries there? Why not in a project directory? Development of one particular program should have no business changing the state of the whole operating system installation.
  • In general, unless you are doing something very unusual, clang (or gcc for that matter) will not need any environment variable to be set. The normal way to influence their behavior is via command line flags. In particular, if the source code and libraries are in a single directory, it doesn't need any -I or -L flags; if you break your project into a small directory tree, it only needs a few -I and -L flags that point to places within the tree.
  • Why are you doing your setup using environment variables that are set in .cshrc? The same user account can be used for developing different projects, which may need different settings.
  • Why are you not using make? Writing a makefile for a simple project is very easy. And the makefile is the easy and traditional way to store special configurations, such as compiler flags. If I had a penny for each time I've added -Wall to CXXFLAGS in my live, I would be slightly less poor.

I was messing with the includes because without that clang just complains that it cannot find the headers. I have llvm40 installed
Code:
ls /usr/local/llvm40 asan_blacklist.txt include            libexec
bin                lib                share

and a very simple program.

Code:
#include <stdio.h>
#include <clang/AST/AST.h>
#include <clang-c/Index.h>

int main(){
        printf("this is a test\n");
        return 0;
}

I removed all the above env variables from my .cshrc and created a new shell, running:
Code:
clang++ test.cpp 
test.cpp:9:10: fatal error: 'clang/AST/AST.h' file not found
#include <clang/AST/AST.h>

clang cannot find the header, the error below is a lot worse.
Why can't clang find it's headers that's in it's own install directory?

Code:
clang++ -I/usr/local/llvm40/include test.cpp
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:17:
In file included from /usr/local/llvm40/include/clang/Basic/LLVM.h:25:
/usr/local/llvm40/include/llvm/ADT/None.h:22:6: warning: scoped
      enumerations are a C++11 extension [-Wc++11-extensions]
enum class NoneType { None };
     ^
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:18:
In file included from /usr/local/llvm40/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/llvm40/include/llvm/ADT/APInt.h:20:
/usr/local/llvm40/include/llvm/Support/MathExtras.h:248:1: error: 
      unknown type name 'constexpr'
constexpr inline uint32_t Hi_32(uint64_t Value) {
^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:248:11: error: 
      expected unqualified-id
constexpr inline uint32_t Hi_32(uint64_t Value) {
          ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:253:1: error: 
      unknown type name 'constexpr'
constexpr inline uint32_t Lo_32(uint64_t Value) {
^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:253:11: error: 
      expected unqualified-id
constexpr inline uint32_t Lo_32(uint64_t Value) {
          ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:259:1: error: 
      unknown type name 'constexpr'
constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) {
^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:259:11: error: 
      expected unqualified-id
constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) {
          ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:264:23: error: 
      unknown type name 'constexpr'
template <unsigned N> constexpr inline bool isInt(int64_t x) {
                      ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:264:33: error: 
      expected unqualified-id
template <unsigned N> constexpr inline bool isInt(int64_t x) {
                                ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:702:10: error: use of
      undeclared identifier 'alignTo'
  return alignTo(Value, Align) - Value;
         ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:707:23: error: 
      unknown type name 'constexpr'
template <unsigned B> constexpr inline int32_t SignExtend32(uint32_t X) {
                      ^
/usr/local/llvm40/include/llvm/Support/MathExtras.h:707:33: error: 
      expected unqualified-id
template <unsigned B> constexpr inline int32_t SignExtend32(uint32_t X) {
                                ^
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:18:
In file included from /usr/local/llvm40/include/llvm/ADT/APFloat.h:20:
/usr/local/llvm40/include/llvm/ADT/APInt.h:291:15: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  APInt(APInt &&that) : BitWidth(that.BitWidth), VAL(that.VAL) {
              ^
/usr/local/llvm40/include/llvm/ADT/APInt.h:661:26: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  APInt &operator=(APInt &&that) {
                         ^
/usr/local/llvm40/include/llvm/ADT/APInt.h:393:14: error: use of
      undeclared identifier 'isPowerOf2_64'
      return isPowerOf2_64(VAL);
             ^
/usr/local/llvm40/include/llvm/ADT/APInt.h:1387:20: error: no member
      named 'countTrailingOnes' in namespace 'llvm'; did you mean
      'countTrailingZeros'?
      return llvm::countTrailingOnes(VAL);
             ~~~~~~^~~~~~~~~~~~~~~~~
                   countTrailingZeros
/usr/local/llvm40/include/llvm/Support/MathExtras.h:111:13: note: 
      'countTrailingZeros' declared here
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
            ^
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:18:
In file included from /usr/local/llvm40/include/llvm/ADT/APFloat.h:20:
/usr/local/llvm40/include/llvm/ADT/APInt.h:1399:20: error: no member
      named 'countPopulation' in namespace 'llvm'
      return llvm::countPopulation(VAL);
             ~~~~~~^
/usr/local/llvm40/include/llvm/ADT/APInt.h:1742:46: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
inline APInt operator+(const APInt &a, APInt &&b) {
                                             ^
/usr/local/llvm40/include/llvm/ADT/APInt.h:1762:46: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
inline APInt operator-(const APInt &a, APInt &&b) {
                                             ^
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:18:
/usr/local/llvm40/include/llvm/ADT/APFloat.h:213:17: warning: 'final'
      keyword is a C++11 extension [-Wc++11-extensions]
class IEEEFloat final : public APFloatBase {
                ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:225:23: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  IEEEFloat(IEEEFloat &&);
                      ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:330:46: warning: deleted
      function definitions are a C++11 extension [-Wc++11-extensions]
  bool operator==(const IEEEFloat &) const = delete;
                                             ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:408:34: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  IEEEFloat &operator=(IEEEFloat &&);
                                 ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:600:21: warning: 'final'
      keyword is a C++11 extension [-Wc++11-extensions]
class DoubleAPFloat final : public APFloatBase {
                    ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:616:48: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  DoubleAPFloat(const fltSemantics &S, APFloat &&First, APFloat &...
                                               ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:616:65: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  ...fltSemantics &S, APFloat &&First, APFloat &&Second);
                                               ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:618:31: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  DoubleAPFloat(DoubleAPFloat &&RHS);
                              ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:622:42: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  DoubleAPFloat &operator=(DoubleAPFloat &&RHS) {
                                         ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:661:15: error: union member
      'IEEE' has a non-trivial copy constructor
    IEEEFloat IEEE;
              ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:224:3: note: because type
      'llvm::detail::IEEEFloat' has a user-provided copy constructor
  IEEEFloat(const IEEEFloat &);
  ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:662:19: error: union member
      'Double' has a non-trivial copy constructor
    DoubleAPFloat Double;
                  ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:617:3: note: because type
      'llvm::detail::DoubleAPFloat' has a user-provided copy constructor
  DoubleAPFloat(const DoubleAPFloat &RHS);
  ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:670:23: warning: variadic
      templates are a C++11 extension [-Wc++11-extensions]
    template <typename... ArgTypes>
                      ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:671:53: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
    Storage(const fltSemantics &Semantics, ArgTypes &&... Args) {
                                                    ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:707:21: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
    Storage(Storage &&RHS) {
                    ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:733:32: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
    Storage &operator=(Storage &&RHS) {
                               ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:750:35: error: too many
      arguments provided to function-like macro invocation
                  std::is_same<T, DoubleAPFloat>::value, "");
                                  ^
/usr/include/c++/v1/__config:727:12: note: macro 'static_assert' defined
      here
#   define static_assert(__b, __m) _Static_assert(__b, __m)
           ^
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:18:
/usr/local/llvm40/include/llvm/ADT/APFloat.h:825:33: warning: defaulted
      function definitions are a C++11 extension [-Wc++11-extensions]
  APFloat(const APFloat &RHS) = default;
                                ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:826:19: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  APFloat(APFloat &&RHS) = default;
                  ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:826:28: warning: defaulted
      function definitions are a C++11 extension [-Wc++11-extensions]
  APFloat(APFloat &&RHS) = default;
                           ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:828:16: warning: defaulted
      function definitions are a C++11 extension [-Wc++11-extensions]
  ~APFloat() = default;
               ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:1016:44: warning: deleted
      function definitions are a C++11 extension [-Wc++11-extensions]
  bool operator==(const APFloat &) const = delete;
                                           ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:1052:44: warning: defaulted
      function definitions are a C++11 extension [-Wc++11-extensions]
  APFloat &operator=(const APFloat &RHS) = default;
                                           ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:1053:30: warning: rvalue
      references are a C++11 extension [-Wc++11-extensions]
  APFloat &operator=(APFloat &&RHS) = default;
                             ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:1053:39: warning: defaulted
      function definitions are a C++11 extension [-Wc++11-extensions]
  APFloat &operator=(APFloat &&RHS) = default;
                                      ^
/usr/local/llvm40/include/llvm/ADT/APFloat.h:1078:10: warning: 
      unelaborated friend declaration is a C++11 extension; specify
      'class' to befriend 'IEEEFloat' (aka 'llvm::detail::IEEEFloat')
      [-Wc++11-extensions]
  friend IEEEFloat;
         ^
         class
/usr/local/llvm40/include/llvm/ADT/APFloat.h:1079:10: warning: 
      unelaborated friend declaration is a C++11 extension; specify
      'class' to befriend 'DoubleAPFloat' (aka
      'llvm::detail::DoubleAPFloat') [-Wc++11-extensions]
  friend DoubleAPFloat;
         ^
         class
/usr/local/llvm40/include/llvm/ADT/APFloat.h:749:5: error: use of
      undeclared identifier 'static_assert'
    static_assert(std::is_same<T, IEEEFloat>::value ||
    ^
In file included from test.cpp:9:
In file included from /usr/local/llvm40/include/clang/AST/AST.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/llvm40/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/llvm40/include/clang/AST/Decl.h:17:
In file included from /usr/local/llvm40/include/clang/AST/APValue.h:20:
In file included from /usr/local/llvm40/include/llvm/ADT/PointerIntPair.h:18:
/usr/local/llvm40/include/llvm/Support/PointerLikeTypeTraits.h:45:61: error: 
      'T' does not refer to a value
  enum { NumLowBitsAvailable = detail::ConstantLog2<alignof(T)>::value };
                                                            ^
/usr/local/llvm40/include/llvm/Support/PointerLikeTypeTraits.h:40:20: note: 
      declared here
template <typename T> class PointerLikeTypeTraits<T *> {
                   ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
28 warnings and 20 errors generated.
 
llvm-config40 will return the flags necessary to find headers, libraries, etc.

clang++40 `llvm-config40 --cxxflags --ldflags` test.cpp -lclang -lLLVM-4.0
 
I still don't understand.

If you remove the following two lines from your little example program:
Code:
#include <clang/AST/AST.h>
#include <clang-c/Index.h>
(leaving only the include of stdio.h), then you have exactly the canonic hallo world program. That needs to compile with the following command: clang++ test.cpp -o test without any errors. Otherwise your clang installation is broken. By the way, I did that test this afternoon on my 11.1-RELEASE machine, and it worked perfectly fine.

What am I missing?
 
llvm-config40 will return the flags necessary to find headers, libraries, etc.

clang++40 `llvm-config40 --cxxflags --ldflags` test.cpp -lclang -lLLVM-4.0

That command does work to build the test program.
Why do I need to use clang++40; I understand clang++ but I have to manually specify version 4.0?
can I put that llvm-config in some environmental variable somewhere? That's a pretty long line just to compile the basic hello world program but with a few clang/llvm headers.
 
I still don't understand.

If you remove the following two lines from your little example program:
Code:
#include <clang/AST/AST.h>
#include <clang-c/Index.h>
(leaving only the include of stdio.h), then you have exactly the canonic hallo world program. That needs to compile with the following command: clang++ test.cpp -o test without any errors. Otherwise your clang installation is broken. By the way, I did that test this afternoon on my 11.1-RELEASE machine, and it worked perfectly fine.

What am I missing?
I am trying to link against llvm/clang.
 
I must be really dense, but I still don't understand your answer.

LLVM is a compiler back-end. Clang is a compiler front-end, which uses LLVM as its back-end. So from a user's point of view, clang and LLVM are one and the same thing. If I have a tiny program "halloworld.c", and I say "clang halloworld.c -o halloworld", then the clang front end will compile my source code (using the LLVM back-end), and then links it (mostly dynamically) against the run-time library that's part of clang/LLVM (and in addition against various operating system libraries). I don't understand what you mean by "link against llvm/clang"; if you use no special include statements in your source, and use the simplest possible clang command line, it just works, and uses LLVM.

Literally, here is my test program, and the command line used to build it:
Code:
> cat halloworld.cpp
#include <stdio.h>
int main(int argc, char* argv[])
{ printf("Hallo world\n");
  return 0; }
> clang++ halloworld.cpp -o halloworld
> ./halloworld
Hallo world
Works without any libraries, flags, or environment variables. You need to explain in more detail what else you want to accomplish.
 
I must be really dense, but I still don't understand your answer.

LLVM is a compiler back-end. Clang is a compiler front-end, which uses LLVM as its back-end. So from a user's point of view, clang and LLVM are one and the same thing. If I have a tiny program "halloworld.c", and I say "clang halloworld.c -o halloworld", then the clang front end will compile my source code (using the LLVM back-end), and then links it (mostly dynamically) against the run-time library that's part of clang/LLVM (and in addition against various operating system libraries). I don't understand what you mean by "link against llvm/clang"; if you use no special include statements in your source, and use the simplest possible clang command line, it just works, and uses LLVM.

Literally, here is my test program, and the command line used to build it:
Code:
> cat halloworld.cpp
#include <stdio.h>
int main(int argc, char* argv[])
{ printf("Hallo world\n");
  return 0; }
> clang++ halloworld.cpp -o halloworld
> ./halloworld
Hallo world
Works without any libraries, flags, or environment variables. You need to explain in more detail what else you want to accomplish.

LLVM/Clang can also be used as a library to create your own tools. Check out their documentation: https://clang.llvm.org/docs/index.html
under the heading using clang as a library

It allows you to use LLVM/Clangs infrastructure to do a lot of things to source code, such as examining the abstract syntax tree, and much more.

Would you like to write your own C or C++ parser? If not, LLVM/Clang can help you.
 
Why do I need to use clang++40; I understand clang++ but I have to manually specify version 4.0?
No, ignore that bit.
can I put that llvm-config in some environmental variable somewhere? That's a pretty long line just to compile the basic hello world program but with a few clang/llvm headers.
Setting CC, CFLAGS, LDFLAGS, ... via environment variables in ~/.cshrc is really ugly and might interfere with compiling other projects (or ports) in unexpected ways. Why not create a small shell script (or Makefile) to build it instead?
 
No, ignore that bit.

Setting CC, CFLAGS, LDFLAGS, ... via environment variables in ~/.cshrc is really ugly and might interfere with compiling other projects (or ports) in unexpected ways. Why not create a small shell script (or Makefile) to build it instead?
This reads like great advice from a seasoned system admin.

Would you have any recommended reading to go along with that post?
 
LLVM/Clang can also be used as a library to create your own tools. Check out their documentation: https://clang.llvm.org/docs/index.html
under the heading using clang as a library

It allows you to use LLVM/Clangs infrastructure to do a lot of things to source code, such as examining the abstract syntax tree, and much more.

Would you like to write your own C or C++ parser? If not, LLVM/Clang can help you.
Yes, I know all that. Matter-of-fact, in my last major project I was pushing to enable using Clang as a (secondary) compiler, to allow us to build source code analysis tools on top of the LLVM infrastructure instead of having to start from scratch or buy commercial products. Been there, done that, got the T-shirt.

But is that what you are trying to accomplish? Or are you trying to simply use Clang/LLVM as a compiler/linker? In either case, you need to start with getting the fundamentals in order: The ability to compile the simple hallo world program. And for that the easiest way is: Start with removing unnecessary #include directives, and the simplest possible command line, to prove that something works. Then, if you need to make things more complex (and use special -L and -I settings), then you need to determine how you are going to automate that. And as was already said multiple times in this thread, using .cshrc is a dangerous and inconvenient way to do it; the standard technique is make files. Once you have source code and make files and everything works, then its time to delve into the rich tools that Clang/LLVM can provide.
 
Hi,

If you are not familiar with Makefiles you can have a look at this document: http://nuclear.mutantstargoat.com/articles/make/. It will show the structure of a Makefile and how you can set your compiler options properly. Then I would say that the easiest is to try to write your own while looking at some from small software (from the port tree for example).

I already ported a some printer drivers and it was pretty interesting. In the past I used CMAKE but make its different than makefiles so I have to learn that now as well.

Thanks for the link, I'll read up on it and become more proficient at them. It's not as archaic as some would make it seem.
 
Yes, I know all that. Matter-of-fact, in my last major project I was pushing to enable using Clang as a (secondary) compiler, to allow us to build source code analysis tools on top of the LLVM infrastructure instead of having to start from scratch or buy commercial products. Been there, done that, got the T-shirt.

But is that what you are trying to accomplish? Or are you trying to simply use Clang/LLVM as a compiler/linker? In either case, you need to start with getting the fundamentals in order: The ability to compile the simple hallo world program. And for that the easiest way is: Start with removing unnecessary #include directives, and the simplest possible command line, to prove that something works. Then, if you need to make things more complex (and use special -L and -I settings), then you need to determine how you are going to automate that. And as was already said multiple times in this thread, using .cshrc is a dangerous and inconvenient way to do it; the standard technique is make files. Once you have source code and make files and everything works, then its time to delve into the rich tools that Clang/LLVM can provide.

I already know how to do those basic things pretty well, I've just never used LLVM/Clang in this way before. What way? I am going to port the Linux KMS graphics stack to FreeBSD so that my GTX 1070 will give me more than 1hr use time on my laptop.

The first thing I did was look at http://kernel.org and noticed that /include/drm/... hasn't changed in a very long time. That means the base is stable. All the changes happens in /driver/gpu/drm.

So first thing is examine all the source code in /include/drm and find all the Linux specific headers and go through replacing them with FreeBSD equivalents. pp-trace will help me get started with that.
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/drm?h=v4.14-rc1

Once that's done I should have a very good understanding of Linux <-> FreeBSD kernel stuffs. After that then I will be able to start to port the /driver/gpu/drm for the different drivers; again replacing the Linux specific bits with their FreeBSD equivalents.

Once this is done that FreeBSD can be on par with Linux in the graphics department, that should bring in more developers and possible give new life to FreeBSD as a desktop/ mobile OS.

I typically check the diffs every so often here: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/?id=v4.14-rc1&id2=v4.13&dt=2

you can also go to http://www.kernel.org and click on the latest version of the Linux kernel to get up to date diff info.

Wouldn't you like to have drivers for the latest video cards without relying on that crashy linuxkpi stuff? I personally do, also once the ground work is laid and documented; future changes could be automated or a lot of the graphics drivers people could actually start writing drivers for Unix on FreeBSD as well as on Linux.

Either way, that's my goal. Do you want to help?
 
I still don't see the connection between your project and Clang/LLVM specifics, but that must be just me not understanding it.

Sadly, none of my FreeBSD machines have graphics adapters that are better than what comes on the system, and they are usually server-class systems or really old laptops (the ThinkPad T61 is the newest one). I don't use graphical user interfaces on FreeBSD, only use it as a server system. So I'm the wrong person to volunteer for this. The project seems definitely worthwhile though.
 
Back
Top