This guide will walk you through the steps to install Beleth on OpenBSD, from cloning the repository to building the program. It will also cover how to resolve common build errors.
Step 1: Clone the Repository.
First, clone the Beleth repository from GitHub to your local machine.
$ git clone https://github.com/chokepoint/Beleth
$ cd Beleth
Step 2: Build the Program
Attempt to build the program using make.
$ make
cc -O2 -pipe -Wall -I/usr/local/include -c beleth.c
cc -O2 -pipe -Wall -I/usr/local/include -c lists.c
cc -O2 -pipe -Wall -I/usr/local/include -c ssh.c
cc beleth.o lists.o ssh.o -L/usr/local/lib/ -lssh2 -o beleth
ld: error: duplicate symbol: verbose
>>> defined at beleth.c
>>> beleth.o:(verbose)
>>> defined at ssh.c
>>> ssh.o:(.bss+0x0)
ld: error: duplicate symbol: t_current
>>> defined at beleth.c
>>> beleth.o:(t_current)
>>> defined at ssh.c
>>> ssh.o:(.bss+0x8)
ld: error: duplicate symbol: pw_head
>>> defined at beleth.c
>>> beleth.o:(pw_head)
>>> defined at ssh.c
>>> ssh.o:(.bss+0x10)
ld: error: duplicate symbol: pw_tail
>>> defined at beleth.c
>>> beleth.o:(pw_tail)
>>> defined at ssh.c
>>> ssh.o:(.bss+0x18)
ld: error: duplicate symbol: pw_tail
>>> defined at beleth.c
>>> beleth.o:(pw_tail)
>>> defined at lists.c
>>> lists.o:(.bss+0x8)
ld: error: duplicate symbol: pw_head
>>> defined at beleth.c
>>> beleth.o:(pw_head)
>>> defined at lists.c
>>> lists.o:(.bss+0x10)
ld: error: duplicate symbol: verbose
>>> defined at beleth.c
>>> beleth.o:(verbose)
>>> defined at lists.c
>>> lists.o:(.bss+0x0)
ld: error: duplicate symbol: t_current
>>> defined at beleth.c
>>> beleth.o:(t_current)
>>> defined at lists.c
>>> lists.o:(.bss+0x18)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error 1 in /home/efek/code/Beleth (Makefile:7 'beleth')
The reason you don't encounter this issue with GCC 4.9 is that different compiler versions handle symbol management and linking processes differently. Newer versions of GCC tend to enforce stricter rules, which can lead to errors when the same symbol is defined multiple times.
Step 3: Resolving Build Errors
If you encounter errors like duplicate symbol definitions, you'll need to adjust the code to ensure variables are correctly declared and used across different source files.
Error: Duplicate Symbol Definitions
The error messages indicate that there are multiple definitions of variables such as verbose, pw_tail, pw_head, and t_current. To resolve this, you should adjust the code to ensure these variables are declared properly.
Remove Duplicate Definitions Ensure that the variables are declared as extern in a header file and defined only once in a source file.
beleth.h
extern int verbose;
lists.h
extern struct t_ctx *t_current;
extern struct pw_list *pw_head;
extern struct pw_list *pw_tail;
Include this header file in beleth.c.
// beleth.c
int verbose = 0; // Define the variable
struct pw_list *pw_head;
struct pw_list *pw_tail;
struct t_ctx *t_current;
Ensure Correct Variable Usage Make sure the variables are used consistently and correctly across the source files.
Step 4: Rebuild the Program
After making the above changes, attempt to build the program again.
$ make
cc -O2 -pipe -Wall -I/usr/local/include -c beleth.c
cc -O2 -pipe -Wall -I/usr/local/include -c lists.c
cc -O2 -pipe -Wall -I/usr/local/include -c ssh.c
cc beleth.o lists.o ssh.o -L/usr/local/lib -lssh2 -o beleth
If the build completes successfully, you should have an executable named beleth.
Conclusion
By following these steps, you should be able to clone the Beleth repository, build the program, and resolve any symbol definition errors. If you encounter additional errors or issues, reviewing the specific error messages and adjusting the code as needed will be necessary.