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

Fix building with clang 15 on OSX #609 #610

Merged
merged 2 commits into from
Sep 29, 2022
Merged

Conversation

wabscale
Copy link
Contributor

The problem is explained in the issue, but to reiterate:

Newer versions of apple's clang will error if there is an undefined reference to TARGET_OS_*. The solution to this is to include the TargetConditionals.h file ahead of any references. The problem originates here:

out.println("#ifdef __ANDROID__");
out.println(" #include <android/log.h>");
out.println("#elif defined(__APPLE__) && defined(__OBJC__)");
out.println(" #include <TargetConditionals.h>");
out.println(" #include <Foundation/Foundation.h>");
out.println("#endif");

The TargetConditionals.h is only included if both __APPLE__ and __OBJC__ are definied. If you use a brew installed llvm (currently version 15), the __APPLE__ will be defined but __OBJC__ is not.

What I have done is made it so that TargetConditionals.h is always included on apple, and the Foundation/Foundation.h is only included when __OBJC__ is defined. The result is this:

#ifdef __ANDROID__
    #include <android/log.h>
#elif defined(__APPLE__)
    #include <TargetConditionals.h>
#endif

#if defined(__OBJC__) 
    #include <Foundation/Foundation.h>
#endif

I've tested this on OSX 12.6, clang 15 (installed via brew install llvm).

@saudet
Copy link
Member

saudet commented Sep 27, 2022

Thanks for the fix! To make sure we don't break anything, we probably want more something like this though:

--- a/src/main/java/org/bytedeco/javacpp/tools/Generator.java
+++ b/src/main/java/org/bytedeco/javacpp/tools/Generator.java
@@ -315,6 +315,8 @@ public class Generator {
         out.println("#elif defined(__APPLE__) && defined(__OBJC__)");
         out.println("    #include <TargetConditionals.h>");
         out.println("    #include <Foundation/Foundation.h>");
+        out.println("#elif defined(__APPLE__)");
+        out.println("    #include <TargetConditionals.h>");
         out.println("#endif");
         out.println();
         out.println("#ifdef __linux__");

@wabscale
Copy link
Contributor Author

Great, I've overwritten the commit with what you have requested.

@saudet saudet merged commit 1edba6d into bytedeco:master Sep 29, 2022
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

Successfully merging this pull request may close these issues.

2 participants