Building Clang From Source

Need support for GhostBSD. Ask here if your question does not fit elsewhere.
Post Reply
terransatellite
Posts: 5
Joined: Sun Dec 11, 2022 6:26 pm

Building Clang From Source

Post 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
chadbsd
Posts: 45
Joined: Thu Oct 05, 2023 8:53 pm

Re: Building Clang From Source

Post 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++
terransatellite
Posts: 5
Joined: Sun Dec 11, 2022 6:26 pm

Re: Building Clang From Source

Post by terransatellite »

Hey thanks alot that worked 8-)

sorry it took so long for me to get back to you
User avatar
ericbsd
Developer
Posts: 2123
Joined: Mon Nov 19, 2012 7:54 pm

Re: Building Clang From Source

Post 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'
Post Reply