Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
votecoffee opened this issue Nov 5, 2020 · 9 comments

Comments

@votecoffee
Copy link

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
Copy link
Contributor

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
Copy link
Author

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

@clalancette
Copy link
Contributor

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

@votecoffee
Copy link
Author

#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
Copy link
Author

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
Copy link
Contributor

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
Copy link
Author

votecoffee commented Nov 11, 2020

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
Copy link
Contributor

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
Copy link
Author

votecoffee commented Nov 12, 2020 via email

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

No branches or pull requests

2 participants