Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot build on OpenBSD #1

Closed
macie opened this issue Jun 23, 2023 · 4 comments
Closed

Cannot build on OpenBSD #1

macie opened this issue Jun 23, 2023 · 4 comments

Comments

@macie
Copy link
Contributor

macie commented Jun 23, 2023

Hi,
when I try to build it on OpenBSD, I've got an error (gmake is a GNU Make):

$ gmake all
clang -std=c99 -Wall -O0 -g -c src/main.c -o src/main.o
clang -std=c99 -Wall -O0 -g -c src/terminal.c -o src/terminal.o
clang -std=c99 -Wall -O0 -g -c src/xwrap.c -o src/xwrap.o
In file included from src/xwrap.c:2:
src/main.h:5:9: warning: '_POSIX_C_SOURCE' macro redefined [-Wmacro-redefined]
#define _POSIX_C_SOURCE 1
        ^
/usr/include/sys/cdefs.h:301:11: note: previous definition is here
#  define _POSIX_C_SOURCE       200112L
          ^
1 warning generated.
clang -std=c99 -Wall -O0 -g -c src/signals.c -o src/signals.o
src/signals.c:134:13: error: use of undeclared identifier 'SIGWINCH'
        xsigaction(SIGWINCH, &winch, NULL);
                   ^
1 error generated.
gmake: *** [Makefile:19: src/signals.o] Error 1

Additional info:

$ uname -rs
OpenBSD 7.3
$ gmake -v
GNU Make 4.3
$ clang -v
OpenBSD clang version 13.0.0
Target: amd64-unknown-openbsd7.3
Thread model: posix
InstalledDir: /usr/bin
@pegvin
Copy link
Owner

pegvin commented Jun 24, 2023

try building it again!

@macie
Copy link
Contributor Author

macie commented Jun 24, 2023

It doesn't work. But after messing up a little (I'm not familiar with C and GNU Make), I found a working solution:

diff --git a/Makefile b/Makefile
index 64b74f2..1b07d19 100644
--- a/Makefile
+++ b/Makefile
@@ -7,6 +7,10 @@ ifeq ($(UNAME_S),FreeBSD)
 	LFLAGS+=-lexecinfo
 endif

+ifeq ($(UNAME_S),OpenBSD)
+	LFLAGS+=-lexecinfo
+endif
+
 bin:=termrec
 obj:=obj

diff --git a/src/main.h b/src/main.h
index cd582a1..97648ce 100644
--- a/src/main.h
+++ b/src/main.h
@@ -13,6 +13,10 @@
 #define __BSD_VISIBLE 1
 #endif

+#ifdef __OpenBSD__
+#define _BSD_SOURCE 1
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/src/signals.c b/src/signals.c
index 3647f49..9413ce8 100644
--- a/src/signals.c
+++ b/src/signals.c
@@ -14,7 +14,6 @@
 #include <execinfo.h>
 #include <fcntl.h>

-#define __BSD_VISIBLE 1
 #include <signal.h>

 #include <termios.h>

After successful compilation I had a problem with starting the program:

$ ./termrec
Segmentation fault (core dumped)

which was caused by invalid number of arguments. So it may be useful for other users to implement something like:

diff --git a/src/main.c b/src/main.c
index 4cb5e5d..520d559 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,6 +15,11 @@ void PrintUsage(const char* name) {
 }

 int main(int argc, char** argv) {
+	if (argc == 1) {
+		PrintUsage(argv[0]);
+		exit(EXIT_FAILURE);
+	}
+
 	struct outargs oa;
 	memset(&oa, 0, sizeof oa);

Anyway, thanks for a great program and your fast reaction

@pegvin
Copy link
Owner

pegvin commented Jun 25, 2023

thanks for pointing out the exact issue! i don't have a BSD-based system and i was too lazy to setup one so these issues are kinda hard to debug...

you didn't raise a PR but in my commits i mentioned you!

thanks alot! do try to rebuild it and see if there's any problem...

@macie
Copy link
Contributor Author

macie commented Jun 25, 2023

Now it can be build on my system. I've configure CI for OpenBSD in #2
Also I've found a bug, but I will describe it in a new issue.

@macie macie closed this as completed Jun 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants