This is an archive of the discontinued LLVM Phabricator instance.

Fix Build error on Mac M1 : error: use of undeclared identifier 'getopt_long_only'; did you mean 'getopt_long'?
AbandonedPublic

Authored by smurfd on May 26 2023, 9:50 AM.

Details

Reviewers
JDevlieghere
Group Reviewers
Restricted Project
Summary

I got build error on Mac M1
lldb/source/Host/common/OptionParser.cpp:46:10: error: use of undeclared identifier 'getopt_long_only'; did you mean 'getopt_long'?

this patch fixes that, two includes needed and also check if __APPLE__. after that building works.

Please set reviewers correct if its not correct, first patch

Diff Detail

Event Timeline

smurfd created this revision.May 26 2023, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 9:50 AM
Herald added a subscriber: krytarowski. · View Herald Transcript
smurfd requested review of this revision.May 26 2023, 9:50 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 26 2023, 9:50 AM
smurfd edited the summary of this revision. (Show Details)May 26 2023, 11:29 AM

What host compiler are you using when you see this error? getopt_long_only is available on macOS. Does this compile for you?

#include <getopt.h>

int main(int argc, char** argv)
{
  struct option longopts[] = {
    { "foo", required_argument, 0, 'f' },
  };
  int i;
  return getopt_long_only(argc, argv, "l::m:r:d",
      longopts, &i);
}

Hey, yeah that compiles.
Im using the standard macos clang ,for Ventura 13.4, xcode 14.3

$ gcc -v
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

this is the way i built llvm from git main from https://github.com/llvm/llvm-project

$ rm -rf build && mkdir build && cd build
$ cmake -DLLVM_ENABLE_PROJECTS="bolt;clang;clang-tools-extra;compiler-rt;lld;lldb;mlir;openmp;polly;flang" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-D_GLIBCXX_HAVE_ENOTRECOVERABLE=1 -DENOTRECOVERABLE=98" -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=$HOME/code/.build/llvm-dev -Bbuild -DLLVM_ENABLE_RUNTIMES="libunwind;libcxxabi;pstl;libcxx" ../llvm
$ make -j8 -Cbuild

after the error i apply this patch and the build finishes.

im using this checkout : dd16cd731dfb4746a351380edc848199cf9631e8 (have also now tried main at the time of writing : a419ec4f256d279c91746a3962dd6dd2da45c304) with the same error

[ 65%] Built target llvm-tapi-diff
[ 65%] Building CXX object lib/DebugInfo/PDB/CMakeFiles/LLVMDebugInfoPDB.dir/PDB.cpp.o
/Users/hellbeard/code/_misc/llvm-project/lldb/source/Host/common/OptionParser.cpp:46:10: error: use of undeclared identifier 'getopt_long_only'; did you mean 'getopt_long'?
  return getopt_long_only(argv.size() - 1, argv.data(), opt_cstr.c_str(),
         ^~~~~~~~~~~~~~~~
         getopt_long
/opt/pkg/include/getopt.h:62:5: note: 'getopt_long' declared here
int getopt_long(int, char * const *, const char *,
    ^
1 error generated.
make[2]: *** [tools/lldb/source/Host/CMakeFiles/lldbHost.dir/common/OptionParser.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
smurfd abandoned this revision.Jun 2 2023, 3:32 PM

Hey, sorry for wasting your time with this. Should have read the error message more carefully.
Its related to pkgsrc missing getopt_long_only() in getopt.h
Checking/filing a bug towards them instead