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

Can't compile on MacOS #58

Open
williamd1k0 opened this issue Aug 9, 2020 · 9 comments
Open

Can't compile on MacOS #58

williamd1k0 opened this issue Aug 9, 2020 · 9 comments

Comments

@williamd1k0
Copy link

Hi, I'm having some problems trying to compile for MacOS.

First of all, I have almost zero experience with MacOS, I'm a Linux user and I'm trying to compile for MacOS using a VM (QEMU) to be able to share this tool with a friend of mine who uses MacOS. If there is a precompiled version for MacOS, I would like to know, so I don't need to compile it myself.

So, I compiled TokTok/c-toxcore and installed it without any problems.
I had to copy/link the .pc file because pkg-config did not find it (toxcore.pc -> libtoxcore.pc).
Then I ran the make -f Makefile.mac command and got the following output:

gcc -g  -I/usr/local/include -I/usr/local/Cellar/libsodium/1.0.18_1/include mach.c -c -o mach.o
In file included from mach.c:2:
./mach.h:8:9: warning: 'CLOCK_REALTIME' macro redefined [-Wmacro-redefined]
#define CLOCK_REALTIME 0
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/time.h:154:9: note: previous definition is here
#define CLOCK_REALTIME _CLOCK_REALTIME
        ^
In file included from mach.c:2:
./mach.h:9:9: warning: 'CLOCK_MONOTONIC' macro redefined [-Wmacro-redefined]
#define CLOCK_MONOTONIC 0
        ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/time.h:156:9: note: previous definition is here
#define CLOCK_MONOTONIC _CLOCK_MONOTONIC
        ^
mach.c:5:5: error: conflicting types for 'clock_gettime'
int clock_gettime(int clk_id, struct timespec *t)
    ^
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/time.h:177:5: note: previous declaration is here
int clock_gettime(clockid_t __clock_id, struct timespec *__tp);
    ^
2 warnings and 1 error generated.
make: *** [mach.o] Error 1

That's it. Sorry if the problem is too stupid, I don't really know how things work on MacOS yet.

@gjedeer
Copy link
Owner

gjedeer commented Aug 11, 2020

Hmm, I wouldn't really know as the makefile for Mac has been submitted by an user (@nCore ), but - from your errors - it seems that the Mac SDK you're using provides the function that was unavailable earlier and mach.c is trying to replace.

Could you edit mach.c and replace

#ifdef __MACH__

with

#if 0

and try building again? Perhaps the hack and the separate Mac makefile is not needed any more.

@gjedeer
Copy link
Owner

gjedeer commented Aug 11, 2020

Looks like it may work, please do try the fix above and report back if it worked, so I can fix the build for everyone

@williamd1k0
Copy link
Author

Hi, thanks for the quick response!

I made the change you recommended and received a new error, but I managed to compile it anyway.

I did the following steps:

  1. I made the change in mach.c.
  2. I tried the make -f Makefile.mac command again and got the following error: main.c:3:10: fatal error: 'tox_bootstrap.h' file not found.
  3. Then I tried make (using the default Makefile) and got the following error: ld: library not found for -lcrt0.o.
  4. I ran make using Makefile.mac again and it completed the process.

I don't know how to fix the default Makefile by myself, but I think the problem is only in the linker command.

@gjedeer
Copy link
Owner

gjedeer commented Aug 12, 2020

Glad it worked for you! The makefile for Mac has been missing the tox_bootstrap.h generator, that's why it worked after you ran the main Makefile.

If you have some time, would you mind testing if my fix worked? On a clean git checkout, preferably:

git clone https://github.com/gjdeer/tuntox.git
git checkout mac-build
make -f Makefile.mac

It should also use toxcore.pc now, but you said you copied/linked that, so it should work anyway.

@williamd1k0
Copy link
Author

Okay, I tested it and got the same first error on mach.c, so I made the manual fix again and compiled it without any other problems.

@gjedeer
Copy link
Owner

gjedeer commented Aug 15, 2020

Aargh, mach.c and mach.h were supposed to be deleted. If it's not a problem: would you mind checking again if it compiles when they're gone?

@williamd1k0
Copy link
Author

It did not compile because client.c was including mach.h.
I removed the include and it still don't compile because of MSG_NOSIGNAL.

I made this patch, so it will work without problems now:

diff --git a/.gitignore b/.gitignore
index 272c4eb..6f2d3a4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,5 +28,8 @@
 *.x86_64
 *.hex
 
+# OS generated files
+.DS_Store
+
 # tuntox related, not needed in repo
 tuntox
diff --git a/mach.h b/mach.h
new file mode 100644
index 0000000..7955c65
--- /dev/null
+++ b/mach.h
@@ -0,0 +1,7 @@
+#ifndef _MACH_H
+#define _MACH_H
+
+// MacOS doesn't support the flag MSG_NOSIGNAL
+#define MSG_NOSIGNAL SO_NOSIGPIPE
+
+#endif
\ No newline at end of file

(I also removed the .DS_Store file because it was bothering me)

@gjedeer
Copy link
Owner

gjedeer commented Aug 17, 2020

Right! Thanks for the patch. Do you want to make a pull request to see your name in the commit log or should I just merge it?

@williamd1k0
Copy link
Author

Ah, no need, but thanks!

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