osrf / osrf_testing_tools_cpp

Common testing tools for C++ which are used for testing in various OSRF projects.
Apache License 2.0
33 stars 28 forks source link

ROS2 Foxy fails to build osrf_testing_tools_cpp because of unresolved external symbol pthread_atfork #56

Open votecoffee opened 3 years ago

votecoffee commented 3 years ago

I ran through the steps to build from source in a VS Command Prompt elevated to admin.

I am following the steps from here: https://index.ros.org/doc/ros2/Installation/Dashing/Windows-Development-Setup/

I get this error:

Failed   <<< osrf_testing_tools_cpp [1min 31s, exited with code 1]

The log file is C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles shows this:

C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\src.c(15,17): warning C4013: 'pthread_atfork' undefined; assuming extern returning int [C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\cmTC_2d2b6.vcxproj]

src.obj : error LNK2019: unresolved external symbol pthread_atfork referenced in function main [C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\cmTC_2d2b6.vcxproj]

The full log file:

Performing C SOURCE FILE Test CMAKE_HAVE_LIBC_PTHREAD failed with the following output:
Change Dir: C:/dev/ros2_foxy/build/osrf_testing_tools_cpp/CMakeFiles/CMakeTmp

Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_2d2b6.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.7.0+b89cb5fde for .NET Framework

Copyright (C) Microsoft Corporation. All rights reserved.

  Microsoft (R) C/C++ Optimizing Compiler Version 19.27.29111 for x64

  src.c

  Copyright (C) Microsoft Corporation.  All rights reserved.

  cl /c /I"C:\vcpkg\installed\x64-windows\include" /Zi /W3 /WX- /diagnostics:column /Od /Ob0 /D WIN32 /D _WINDOWS /D CMAKE_HAVE_LIBC_PTHREAD /D "CMAKE_INTDIR=\"Debug\"" /D _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"cmTC_2d2b6.dir\Debug\\" /Fd"cmTC_2d2b6.dir\Debug\vc142.pdb" /Gd /TC /errorReport:queue C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\src.c

C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\src.c(15,17): warning C4013: 'pthread_atfork' undefined; assuming extern returning int [C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\cmTC_2d2b6.vcxproj]

src.obj : error LNK2019: unresolved external symbol pthread_atfork referenced in function main [C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\cmTC_2d2b6.vcxproj]

C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\Debug\cmTC_2d2b6.exe : fatal error LNK1120: 1 unresolved externals [C:\dev\ros2_foxy\build\osrf_testing_tools_cpp\CMakeFiles\CMakeTmp\cmTC_2d2b6.vcxproj]

Source file was:
#include <pthread.h>

void* test_func(void* data)
{
  return data;
}

int main(void)
{
  pthread_t thread;
  pthread_create(&thread, NULL, test_func, NULL);
  pthread_detach(thread);
  pthread_cancel(thread);
  pthread_join(thread, NULL);
  pthread_atfork(NULL, NULL, NULL);
  pthread_exit(NULL);

  return 0;
}
clalancette commented 3 years ago

It looks like you are mixing Dashing and Foxy here. You shouldn't do that; it definitely won't work, there are a lot of changes between them. What version are you actually trying to build?

votecoffee commented 3 years ago

Sorry, I meant https://index.ros.org/doc/ros2/Installation/Foxy/Windows-Development-Setup/ I am installing Foxy

clalancette commented 3 years ago

All right, can you give the exact steps you used to get to this point then?

votecoffee commented 3 years ago

Install Chocolatey

https://chocolatey.org/install

Open powershell as administrator

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

Add to %PATH%: %ALLUSERSPROFILE%\chocolatey\bin

Install prereqs

https://index.ros.org/doc/ros2/Installation/Foxy/Windows-Install-Binary

reopen powershell as administrator

ROS2 expects c:\python38, so a newer version of 3.8 is fine

choco install -y python --version 3.8.5 choco install -y vcredist2013 vcredist2017 vcredist140

Add to %PATH%: C:\Python38

Add to %PATH%: C:\Python38\Scripts

Install OpenSSL

Install Visual Studio 2019

Install opencv

setx -m OpenCV_DIR C:\opencv

Install CMake

Install dependencies

https://github.com/ros2/choco-packages/releases/tag/2020-02-24

Download above to C:\dev\src

choco install -y -s C:\dev\src asio cunit eigen tinyxml-usestl tinyxml2 log4cxx bullet --force --pre python.exe -m pip install -U catkin_pkg cryptography empy ifcfg lark-parser lxml netifaces numpy opencv-python pyparsing pyyaml setuptools c:\Python38\python.exe -m pip install -U catkin_pkg cryptography empy ifcfg lark-parser lxml netifaces numpy opencv-python pyparsing pyyaml setuptools pip install -U pytest pytest-mock coverage mock pip3 install -U pytest pytest-mock coverage mock python -m pip install -U pydot PyQt5 c:\Python38\python.exe -m pip install -U pydot PyQt5 choco install graphviz --force

Build from source

https://index.ros.org/doc/ros2/Installation/Foxy/Windows-Development-Setup/

If you get the below error when running the example, you need to build from source instead

RuntimeError: Failed to initialize init_options: failed to load shared library of rmw implementation: C:\dev\ros2_foxy\bin/rmw_fastrtps_cpp.dll Exception: LoadLibrary error: 126, at C:\ci\ws\src\ros2\rcutils\src\shared_library.c:72, at C:\ci\ws\src\ros2\rmw_implementation\rmw_implementation\src\functions.cpp:64, at C:\ci\ws\src\ros2\rcl\rcl\src\rcl\init_options.c:55

choco install -y git choco install -y patch pip install -U vcstool pip3 install -U vcstool pip install -U colcon-common-extensions pip3 install -U colcon-common-extensions choco install -y curl c:\python38\python.exe -m pip install -U setuptools pip pip install -U catkin_pkg EmPy lark-parser lxml numpy pyparsing pyyaml pip3 install -U catkin_pkg EmPy lark-parser lxml numpy pyparsing pyyaml pip install -U pytest coverage mock pip3 install -U pytest coverage mock pip install -U flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes mypy pep8 pydocstyle pip3 install -U flake8 flake8-blind-except flake8-builtins flake8-class-newline flake8-comprehensions flake8-deprecated flake8-docstrings flake8-import-order flake8-quotes mypy pep8 pydocstyle choco install -y cppcheck

Download the 64 bit binary archives of libxml2 (and its dependencies iconv and zlib)

https://www.zlatkovic.com/pub/libxml/64bit/

Unpack all archives into e.g. C:\xmllint

Add C:\xmllint\bin to the PATH

Install QT5

https://www.qt.io/download

Select the Open Source version and then the Qt Online Installer for Windows.

install it to the default location of C:\Qt

setx -m Qt5_DIR C:\Qt\5.15.0\msvc2019_64 pip install -U pydot PyQt5 pip3 install -U pydot PyQt5

Run from a visual studio cmd prompt as admin

choco upgrade all pip install pipupgrade pipupgrade --verbose --latest --yes

delete \dev\ros2_foxy if it exists

md \dev\ros2_foxy\src cd \dev\ros2_foxy curl -sk https://raw.githubusercontent.com/ros2/ros2/foxy/ros2.repos -o ros2.repos vcs import src < ros2.repos colcon build --merge-install

votecoffee commented 3 years ago

I also verified my QT path matched I have python 3.9 installed as well but only the directory for python 3.8.5 is in my path variable

clalancette commented 3 years ago

I gave a quick try reproducing here, and I couldn't do it. It's also not failing on the Foxy CI jobs we've run recently (like https://ci.ros2.org/job/ci_windows/12997).

Unfortunately, I don't know what else to suggest. It probably is some difference in how the environment is setup, but it's not clear to me what that is.

One thing you could do is to use the Windows binaries from https://github.com/ros2/ros2/releases . That will at least get you past this issue.

votecoffee commented 3 years ago

Thanks for the effort and help.

I created a clean VM and retried but that also failed. It was a different message but the same underlying cause. It appears to be related to a pthreads dependency. I installed pthreads using mingw and vcpkg (both x64 and x86). I'm compiling as x64. Any thoughts on how you fulfilled the pthreads requirement? I'm pretty sure that's the underlying problem on my end.

clalancette commented 3 years ago

That's part of the thing that is weird; it shouldn't even be trying to build that stuff on Windows. That is Linux-only.

But maybe the fact that MinGW is in the mix is causing our detection logic to mistake it for something else. If you remove MinGW, does it work then?

votecoffee commented 3 years ago

That’s a good tip. I’ll start again with a clean vm and see what I can figure out.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Chris Lalancette notifications@github.com Sent: Wednesday, November 11, 2020 1:04:17 PM To: osrf/osrf_testing_tools_cpp osrf_testing_tools_cpp@noreply.github.com Cc: votecoffee votecoffee@outlook.com; Author author@noreply.github.com Subject: Re: [osrf/osrf_testing_tools_cpp] ROS2 Foxy fails to build osrf_testing_tools_cpp because of unresolved external symbol pthread_atfork (#56)

That's part of the thing that is weird; it shouldn't even be trying to build that stuff on Windows. That is Linux-only.

But maybe the fact that MinGW is in the mix is causing our detection logic to mistake it for something else. If you remove MinGW, does it work then?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fosrf%2Fosrf_testing_tools_cpp%2Fissues%2F56%23issuecomment-725575079&data=04%7C01%7C%7Cd610814ae3cc476ad76308d8866c35a5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637407146592283183%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=E2V%2F0mNmkDYNVquptg12LICeAbImjIHFooxsCOl%2BOF4%3D&reserved=0, or unsubscribehttps://nam03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABY3FIYIT2FQPDVHI4C5GY3SPLG2DANCNFSM4TLKHLKQ&data=04%7C01%7C%7Cd610814ae3cc476ad76308d8866c35a5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C637407146592303177%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=u3abslVBkEcwEFTYd%2BRCk3aYVgAmpSrxOfZhIktieQE%3D&reserved=0.