Skip to content

Add macOS compatibility for CPU core detection#72

Open
Bohaska wants to merge 1 commit intoBGI-flexlab:masterfrom
Bohaska:macos
Open

Add macOS compatibility for CPU core detection#72
Bohaska wants to merge 1 commit intoBGI-flexlab:masterfrom
Bohaska:macos

Conversation

@Bohaska
Copy link

@Bohaska Bohaska commented Aug 28, 2025

Hello BGI-flexlab team,

This Pull Request addresses a build error I encountered when compiling SOAPnuke on macOS systems.

Problem
When attempting to build SOAPnuke on macOS, the compilation process fails with the following error:

src/process_argv.cpp:9:10: fatal error: 'sys/sysinfo.h' file not found

This is because sys/sysinfo.h and the get_nprocs() function are part of the GNU C Library (glibc) and are not available on macOS (which uses a BSD-derived system).

Proposed Solution
This PR introduces conditional compilation to use platform-specific headers and functions for retrieving the number of CPU processors. After implementing this PR, I was able to compile SOAPnuke on MacOS.

Changes Made

  1. Conditional Header Include: Replaced the direct inclusion of "sys/sysinfo.h" with a conditional block that includes <unistd.h> for macOS (__APPLE__) and retains "sys/sysinfo.h" for other systems.
  2. Conditional CPU Count Retrieval: Replaced the get_nprocs() function call with sysconf(_SC_NPROCESSORS_ONLN) within a conditional block for macOS. This ensures that the correct POSIX-compliant method is used on Apple platforms.

These changes ensure that SOAPnuke can be successfully compiled and run on macOS, significantly improving its portability and accessibility for users that use MacOS.

Thank you for considering this improvement.

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.

1 participant