Page 1 of 1

Building Clang From Source

Posted: Sat Jul 06, 2024 9:18 pm
by terransatellite
Hello I am trying to build clang from source, and I googled my question but it doesn't come up with anything.. "build clang from source freebsd" doesn't give any information on it. And my problem, is that my c/c++ compiler is missing a few files, I cannot find them with "pkg search" so it cannot find these files, and I have tried using gcc and freebsd's version of clang, neither works, same error.

Code: Select all

    /usr/local/bin/ld: cannot find crt1.o: No such file or directory
    /usr/local/bin/ld: cannot find crti.o: No such file or directory
    /usr/local/bin/ld: cannot find -lc: No such file or directory
    /usr/local/bin/ld: cannot find crtn.o: No such file or directory
I hope you can help me find these files, or tell me whats wrong with my c/c++ compilers

Re: Building Clang From Source

Posted: Sun Jul 07, 2024 7:53 am
by chadbsd
The errors you're encountering indicate that the necessary C runtime files (`crt1.o`, `crti.o`, `crtn.o`) and the standard C library (`libc`) are missing. These files are part of the base system in FreeBSD (and GhostBSD, which is based on FreeBSD) and are typically located in the `/usr/lib` directory.

Here are the steps you can follow to resolve this issue:

1. Install the necessary base system files:
Ensure that the base system files are correctly installed. You can try reinstalling the base system libraries.

For FreeBSD:
sudo pkg install -f FreeBSD-lib

For GhostBSD:
sudo pkg install os-generic-userland-devtools

NOTE: When using GhostBSD using pkgbase, use: sudo pkg install -f FreeBSD-lib.

2. Install the development tools:
Ensure you have all the development tools installed, including `libc`, `clang`, and `gcc`.

sudo pkg install clang gcc

3. Check for the required files:
Verify that the required files are present in the `/usr/lib` directory. You should have the following files:

- `/usr/lib/crt1.o`
- `/usr/lib/crti.o`
- `/usr/lib/crtn.o`
- `/usr/lib/libc.so`

If these files are missing, it indicates a problem with your base system installation.

4. Build Clang from Source:
If you still wish to build Clang from source, you can follow these steps:

a. Update the Ports Collection:
Ensure your ports collection is up-to-date.

sudo portsnap fetch update

b. Navigate to the Clang Port Directory:
Go to the Clang port directory.

cd /usr/ports/devel/llvm

c. Compile and Install Clang:
Compile and install Clang from the ports collection.

sudo make install clean

5. Set the Default Compiler:
If you want to set Clang as your default compiler, you can update your environment variables.

For sh:

setenv CC clang
setenv CXX clang++

Or for bash:

export CC=clang
export CXX=clang++

Re: Building Clang From Source

Posted: Sun Aug 18, 2024 6:33 pm
by terransatellite
Hey thanks alot that worked 8-)

sorry it took so long for me to get back to you

Re: Building Clang From Source

Posted: Sat Sep 07, 2024 10:15 pm
by ericbsd
It has changed lately. See https://ghostbsd-documentation-portal.r ... n-ghostbsd, and you now have to do sudo pkg install -g 'GhostBSD*-dev'