osrm-backend icon indicating copy to clipboard operation
osrm-backend copied to clipboard

osrm-backend-5.27.1 not compiling on Sonoma14.2 on MacBook Air

Open 1ashishdixit opened this issue 1 year ago • 3 comments

Issue

I have been trying for last couple of days for OSRM to compile on my MacBook Air. I have tried everything that is available online, including downloading OSRM from homebrew https://formulae.brew.sh/formula/osrm-backend, as well as downloading OSRM from the source archives .

Steps to reproduce

wget https://github.com/Project-OSRM/osrm-backend/archive/v5.27.1.tar.gz tar -xzf v5.27.1.tar.gz cd osrm-backend-5.27.1 mkdir -p build cd build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . At this stage I get following errors: [ 0%] Building CXX object CMakeFiles/UTIL.dir/src/util/coordinate_calculation.cpp.o /opt/homebrew/Cellar/osrm-backend-5.27.1/src/util/coordinate_calculation.cpp:332:5: error: ignoring return value of function declared with 'nodiscard' attribute [-Werror,-Wunused-result] std::find_if(std::begin(lhs), std::end(lhs), compute_minimum_distance_in_rhs); ^~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /opt/homebrew/Cellar/osrm-backend-5.27.1/src/util/coordinate_calculation.cpp:1: /opt/homebrew/Cellar/osrm-backend-5.27.1/include/util/coordinate_calculation.hpp:209:5: error: ignoring return value of function declared with 'nodiscard' attribute [-Werror,-Wunused-result] std::adjacent_find(begin, end, compute_minimum_distance); ^~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /opt/homebrew/Cellar/osrm-backend-5.27.1/src/util/coordinate_calculation.cpp:328:35: note: in instantiation of function template specialization 'osrm::util::coordinate_calculation::findClosestDistance<std::__wrap_iter<const osrm::util::Coordinate *>>' requested here std::min(current_min, findClosestDistance(coordinate, rhs.begin(), rhs.end())); ^ 2 errors generated. make[2]: *** [CMakeFiles/UTIL.dir/src/util/coordinate_calculation.cpp.o] Error 1 make[1]: *** [CMakeFiles/UTIL.dir/all] Error 2 make: *** [all] Error 2

Specifications

  • Downloaded all the dependencies for Mac OS: brew install boost git cmake libzip libxml2 lua tbb ccache pkg-config brew install GDAL
  • Operating system: Sonoma 14.1
  • Hardware: MacBook Air

Please help me. I am stuck.

1ashishdixit avatar Feb 24 '24 22:02 1ashishdixit

/opt/homebrew/Cellar/osrm-backend-5.27.1/src/util/coordinate_calculation.cpp:332:5

smth is wrong with your build (assuming you're not really building from /opt/homebrew). I'd remove the brew version and try again

nilsnolde avatar Feb 24 '24 22:02 nilsnolde

I greatly appreciate a quick response. I had 2 versions of OSRM - one that was pulled using %brew install osrm-backend and the other that was pulled using %wget https://github.com/Project-OSRM/osrm-backend/archive/v5.27.1.tar.gz

The brew version was installed in 5.27.1_4 directory. I removed it by giving the command %rm -R *
zsh: sure you want to delete all 10 files in /opt/homebrew/Cellar/osrm-backend/5.27.1_4 [yn]? y

Is that what you meant by "I'd remove the brew version and try again".

When I run % cmake .. -DCMAKE_BUILD_TYPE=Release on the source code I had pulled using wget, I get lot of warnings: CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Deprecation Warning at CMakeLists.txt:55 (cmake_policy): The OLD behavior for policy CMP0048 will be removed from a future version of CMake.

The cmake-policies(7) manual explains that the OLD behaviors of all policies are deprecated and that a policy should be set to OLD only under specific short-term circumstances. Projects should be ported to the NEW behavior and not rely on setting a policy to OLD.

CMake Deprecation Warning at cmake/JSONParser.cmake:4 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions. Call Stack (most recent call first): CMakeLists.txt:74 (include)

-- Building on a 64 bit system CMake Warning at CMakeLists.txt:209 (message): GNU gold linker isn't available.

-- Configuring OSRM in release mode -- Configuring release mode optimizations -- Performing Test SUPPORTS_CXXFLAG_strict_overflow=2 -- Performing Test SUPPORTS_CXXFLAG_strict_overflow=2 - Success -- Performing Test SUPPORTS_CFLAG_strict_overflow=2 -- Performing Test SUPPORTS_CFLAG_strict_overflow=2 - Success -- Flag -Wduplicated-cond is unsupported -- Flag -Wduplicated-cond is unsupported -- Flag -Wbool-compare is unsupported -- Flag -Wbool-compare is unsupported -- Flag -Wlogical-op is unsupported -- Flag -Wlogical-op is unsupported -- Flag -Wmaybe-uninitialized is unsupported -- Flag -Wmaybe-uninitialized is unsupported -- Flag -Wno-return-local-addr is unsupported -- Flag -Wno-return-local-addr is unsupported -- Flag -Wtrampolines is unsupported -- Flag -Wtrampolines is unsupported -- Using unknown linker, not setting linker optimizations CMake Warning (dev) at CMakeLists.txt:412 (exec_program): Policy CMP0153 is not set: The exec_program command should not be called. Run "cmake --help-policy CMP0153" for policy details. Use the cmake_policy command to set the policy and suppress this warning.

Use execute_process() instead. This warning is for project developers. Use -Wno-dev to suppress it.

-- linking against libc++ CMake Deprecation Warning at third_party/flatbuffers/CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 3.5 will be removed from a future version of CMake.

Update the VERSION argument value or use a ... suffix to tell CMake that the project does not need compatibility with older versions.

CMake Warning (dev) at /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:438 (message): The package name passed to find_package_handle_standard_args (PkgConfig) does not match the name of the calling package (Lua). This can lead to problems in calling code that expects find_package result variables (e.g., _FOUND) to follow a certain pattern. Call Stack (most recent call first): /opt/homebrew/Cellar/cmake/3.28.3/share/cmake/Modules/FindPkgConfig.cmake:99 (find_package_handle_standard_args) cmake/FindLua.cmake:39 (include) CMakeLists.txt:572 (find_package) This warning is for project developers. Use -Wno-dev to suppress it.

-- Using Lua 5.4.6 -- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) -- Using ccache to speed up incremental builds -- Configuring done (1.4s) -- Generating done (0.2s) -- Build files have been written to: /opt/homebrew/Cellar/osrm-backend-5.27.1/build

After this I run the same command %cmake --build . and get the same 2errors as I had previously reported

Any help would be greatly appreciated.

1ashishdixit avatar Feb 25 '24 01:02 1ashishdixit

I even downloaded v5.27.0 in /Users/project/code directory. Same 2 errors as before: error: ignoring return value of function declared with 'nodiscard' attribute [-Werror,-Wunused-result] std::find_if(std::begin(lhs), std::end(lhs), compute_minimum_distance_in_rhs);

: error: ignoring return value of function declared with 'nodiscard' attribute [-Werror,-Wunused-result] std::adjacent_find(begin, end, compute_minimum_distance); ^~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1ashishdixit avatar Feb 25 '24 17:02 1ashishdixit

Any suggestions anyone?

1ashishdixit avatar Feb 29 '24 15:02 1ashishdixit

These errors are not actually errors, but warnings treated as errors. We treat all warnings as errors: https://github.com/Project-OSRM/osrm-backend/blob/31e31a63d062fb804f5f4695ed3036ca7a269ead/cmake/warnings.cmake#L52 and basically in newer version of compiler new warnings were added… Ideally we should have an option to disable it, but I think as a workaround you can:

  • comment this line above
  • pass flags to disable warnings (can be done via CXXFLAGS env variable)

SiarheiFedartsou avatar Mar 03 '24 20:03 SiarheiFedartsou

Thanks for the feedback. I was able to fix these issues by following steps listed below (anyone looking to see how, please check at the bottom). Now I am running in a new issue. I have a .c file that has the main() function. In that file I make a call to callLibOSRM() that is essentially example.cpp file that I have created in callLibOSRM.cpp. In this file here are my definitions:

extern "C" int callLibOSRM(void); int callLibOSRM(void){ example.cpp }

I get this error while building : ld: Undefined symbols: osrm::OSRM::OSRM(osrm::engine::EngineConfig&), referenced from: _callLibOSRM in CallLibOSRM.o osrm::OSRM::~OSRM(), referenced from: _callLibOSRM in CallLibOSRM.o _callLibOSRM in CallLibOSRM.o osrm::OSRM::Route(osrm::engine::api::RouteParameters const&, mapbox::util::variant<osrm::util::json::Object, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator>, flatbuffers::FlatBufferBuilder>&) const, referenced from: _callLibOSRM in CallLibOSRM.o clang: error: linker command failed with exit code 1 (use -v to see invocation)

Can you please let me know how to fix this? This was my original issue which led me to trying to build the libOSRM using build.

Now, going back to my previous issue, here is how I have solved it. I faced 2 type of errors:

  1. error: ignoring return value of function declared with 'nodiscard' attribute [-Werror,-Wunused-result] std::adjacent_find(path.begin(), path.end(), augment_one); ^~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.

To fix that all I did was added static_cast(error_statement) so it looks some thing like this in the example above:

static_cast(std::adjacent_find(path.begin(), path.end(), augment_one));

  1. error: variable 'current_level' set but not used [-Werror,-Wunused-but-set-variable] unsigned current_level = 0;

To fix that all I did was added a line like this after the unused variable: (void)current_level;

1ashishdixit avatar Mar 04 '24 01:03 1ashishdixit

Can someone help me please?

1ashishdixit avatar Mar 09 '24 19:03 1ashishdixit

After lot of research I was able to fix my problems, This thread can be closed.

In the "Build Phases" tab of the Xcode target settings, expand the "Link Binary with Libraries" section. Click the "+" button and select the library you want to link against from the list. I added following libraries here: libosrm.a, libboost_iostream.a, libboost_filesystem.a, libboost_thread-mt.a (please note that the libboost files were at /opt/homebrew/Cellar/boost/1.84.0/lib/ . I was unable to add the file from the XCode, so i just copied them to my libosrm/build folder and copied from there)

After that, in XCode Project navigator on the left, drag these 4 files from under Frameworks and copy under the files which call libOSRM. And Voila - it ran!

1ashishdixit avatar Mar 13 '24 17:03 1ashishdixit