Skip to content
This repository was archived by the owner on Dec 29, 2025. It is now read-only.

Conversation

@theory
Copy link
Contributor

@theory theory commented Sep 12, 2025

Fix compile error on macOS

I was getting this error on macOS:

ld: library 'c++' not found
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

Took a while to track down the issue, but it turned out this warning at the end of cmake was key:

CMake Warning at src/CMakeLists.txt:40 (target_link_libraries):
  Target "clickhouse_fdw" requests linking to directory
  "/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk".  Targets may link
  only to libraries.  CMake is dropping the item.

This is fine, except that that CMake doesn't remove the option this directory points to. The option is stored by pg_config; you can see it here:

pg_config --ldflags         
-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk -L/opt/homebrew/opt/readline/lib -Wl,-dead_strip_dylibs

What we need to do is remove both the macOS SDK and -isysroot. So add a section to CMakeLists.txt that uses REGEX REPLACE to remove the complete option from the output of pg_config on macOS.

I was getting this error on macOS:

```
ld: library 'c++' not found
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
```

Took a while to track down the issue, but it turned out this warning at
the end of `cmake` was key:

```
CMake Warning at src/CMakeLists.txt:40 (target_link_libraries):
  Target "clickhouse_fdw" requests linking to directory
  "/Library/Developer/CommandLineTools/SDKs/MacOSX15.sdk".  Targets may link
  only to libraries.  CMake is dropping the item.
```

This is fine, except that that CMake doesn't remove the option this
directory points to. The option is stored by `pg_config`; you can see it
here:

``` console
pg_config --ldflags
-isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX15.5.sdk -L/opt/homebrew/opt/readline/lib -Wl,-dead_strip_dylibs
```

What we need to do is remove both the macOS SDK and `-isysroot`. So add
a section to `CMakeLists.txt` that uses `REGEX REPLACE` to remove the
complete option from the output of `pg_config` on macOS.
@theory
Copy link
Contributor Author

theory commented Sep 12, 2025

Oddly it named the resulting file clickhouse_fdw.so. I renamed it to clickhouse_fdw.dylib and it worked very well. Couldn't see where to fix that in a few minutes of digging.

@ildus ildus merged commit 5bdf0c2 into ildus:master Sep 14, 2025
12 checks passed
@ildus
Copy link
Owner

ildus commented Sep 14, 2025

Thanks!

@theory
Copy link
Contributor Author

theory commented Sep 15, 2025

Thanks. Any thoughts on how to fix the incorrect file name?

@theory theory deleted the fix-macos branch September 16, 2025 17:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants