undefined reference to symbol 'pthread_setname_np##GLIBC_2.12' Haskell Stack error on OpenSuse42.3 - haskell

I have installed haskell stack and I'm trying to setup ghc for the same. stack version is
stack --version
Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1
I have updated the ~/.stack/global-project/stack.yaml as below
# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project. Settings here do _not_ act as
# defaults for all projects. To change stack's default settings, edit
# '/home/rajkumar/.stack/config.yaml' instead.
#
# For more information about stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
#
flags: {}
extra-package-dbs: []
packages: []
extra-deps: []
resolver: ghc-8.2.1
Then I run stack setup command and got the below error -
stack setup
The GHC located at /home/rajkumar/.stack/programs/x86_64-linux/ghc-8.2.1/bin/ghc failed to compile a sanity check. Please see:
http://docs.haskellstack.org/en/stable/install_and_upgrade/
for more information. Exception was:
Running /home/rajkumar/.stack/programs/x86_64-linux/ghc-8.2.1/bin/ghc /tmp/stack-sanity-check3048/Main.hs -no-user-package-db in directory /tmp/stack-sanity-check3048/ exited with ExitFailure 1
[1 of 1] Compiling Main ( /tmp/stack-sanity-check3048/Main.hs, /tmp/stack-sanity-check3048/Main.o )
Linking /tmp/stack-sanity-check3048/Main ...
/usr/bin/ld.bfd: /home/rajkumar/.stack/programs/x86_64-linux/ghc-8.2.1/lib64/ghc-8.2.1/rts/libHSrts.a(OSThreads.o): undefined reference to symbol 'pthread_setname_np##GLIBC_2.12'
/lib64/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
`gcc' failed in phase `Linker'. (Exit code: 1)

So maybe the problem is that you need GLIBC_2.12 installed on your machine and not 2.26
No, that is not the issue. GLIBC-2.26 most certainly provides the pthread_setname_np##GLIBC_2.12 symbol (see this answer to understand how symbol versioning works).
You can verify that the symbol is indeed available in your GLIBC-2.26 like so:
$ readelf -Ws /lib/x86_64-linux-gnu/libpthread.so.0 | grep pthread_setname_np
89: 00000000000113c0 258 FUNC GLOBAL DEFAULT 13 pthread_setname_np##GLIBC_2.12
704: 00000000000113c0 258 FUNC GLOBAL DEFAULT 13 pthread_setname_np
(Above command was executed on a system with GLIBC-2.19, but you'll get the same output on a system with GLIBC-2.26).
Now to what your real problem is: libHSrts.a(OSThreads.o) references pthread_setname_np (and likely other pthread_* symbols, but you are not linking with -pthread or -lpthread flag.
I don't know where to add this flag to GHC, but once you find that out, your problem will be solved.

Related

Why does/can my build access sysctl on Linux?

I inherited a C++ code with a dependency to OpenMPI that I want to delegate to Conan and CMake, and the automated build has a strange (to me at least) behavior related to sysctl that I want to understand.
How I tried to do it
I declared the required dependencies in my root CMakeLists.txt:
Note: I added the full list of requirements because I also suspect that some of them may be in conflict? That happened before with boost, that forced me to set explicitly zlib (if i remember correctly).
# stuff ...
conan_cmake_configure(
REQUIRES
zlib/1.2.12
mp-units/0.7.0
boost/1.79.0
openmpi/4.1.0
gsl/2.7
cspice/0067
GENERATORS
cmake
# that is required for cspice
CMakeDeps
CMakeToolchain
)
# more stuff ...
and then in the application CmakeLists.txt I find, include and link the executable to the required libraries:
add_executable(spock main.cpp)
find_package(cspice REQUIRED)
find_package(openmpi REQUIRED)
target_include_directories(
spock PRIVATE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
openmpi_INCLUDE_DIRS
cspice_INCLUDE_DIRS
)
target_link_libraries(spock
CONAN_PKG::boost
CONAN_PKG::mp-units
openmpi::openmpi
cspice::cspice
)
# We need C++ 20 activated with the concepts library
target_compile_features(spock PUBLIC cxx_std_20)
Problem: undefined reference to sysctl ... on my local system only.
Building on my local machine with CMake 3.23.2 results in the following error message:
Consolidate compiler generated dependencies of target spock
[ 25%] Building CXX object src/CMakeFiles/spock.dir/main.cpp.o
^[[A^[[A[ 50%] Linking CXX executable ../bin/spock
/usr/bin/ld: /home/becheler/.conan/data/openmpi/4.1.0/_/_/package/8f7048d1bf6fc2a7985eb087c34e69a5e64f6c86/lib/libopen-pal.a(evutil_rand.o): in function `arc4_stir.isra.0':
evutil_rand.c:(.text+0x3d2): undefined reference to `sysctl'
collect2: error: ld returned 1 exit status
gmake[2]: *** [src/CMakeFiles/spock.dir/build.make:146: bin/spock] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:135: src/CMakeFiles/spock.dir/all] Error 2
gmake: *** [Makefile:146: all] Error 2
However, the same build on Github workflows on Ubuntu 20.04 works. What is weird. The only difference before apart the distribution version is that github wokflows use higher privileges than me on local (I believe?).
What I tried so far
I've been trying to read about what this sysctlreference is. And I found conflicting information:
Frrom this man page:
The sysctl() function retrieves system information and allows processes with appropriate privileges to set system information.
this similar SO question came to the conclusion that
Linux does not support this function (other OS like MacOS or FreeBSD support it)
A comment from the same post concludes that in Linux,
these details can be obtained by reading the kernel-provided
pseudofiles /proc/cpuinfo and /proc/meminfo
So here is my question: why does it compile at all on the remote server if this command is not supposed to exist on the OS used?

Error building package regex-posix-0.96.0.0 with Stack

I'm trying to compile a new Haskell project with Stack, but I'm getting this error message:
$ stack build
WARNING: Ignoring regex-posix's bounds on base (<0 && >=4.3 && <4.16); using base-4.14.1.0.
Reason: trusting snapshot over cabal file dependency information.
regex-posix > configure
regex-posix > Configuring regex-posix-0.96.0.0...
regex-posix > build
regex-posix > Preprocessing library for regex-posix-0.96.0.0..
regex-posix > compiling .stack-work\dist\274b403a\build\Text\Regex\Posix\Wrap_hsc_make.c failed (exit code 1)
regex-posix > rsp file was: ".stack-work\\dist\\274b403a\\build\\Text\\Regex\\Posix\\hsc5BFC.rsp"
regex-posix > command was: C:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\../mingw/bin\gcc.exe -c .stack-work\dist\274b403a\build\Text\Regex\Posix\Wrap_hsc_make.c -o .stack-work\dist\274b403a\build\Text\Regex\Posix\Wrap_hsc_make.o -D__GLASGOW_HASKELL__=810 -Dmingw32_BUILD_OS=1 -Dx86_64_BUILD_ARCH=1 -Dmingw32_HOST_OS=1 -Dx86_64_HOST_ARCH=1 -Icbits -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\274b403a\build\cbits -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -I.stack-work\dist\274b403a\build\autogen -I.stack-work\dist\274b403a\build\global-autogen -include .stack-work\dist\274b403a\build\autogen\cabal_macros.h -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\msys2-20180531\mingw64\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\bytestring-0.10.12.0\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\base-4.14.1.0\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib\integer-gmp-1.0.3.0\include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4\lib/include -IC:\Users\mark\AppData\Local\Programs\stack\x86_64-windows\ghc-8.10.4/lib/include/
regex-posix > error: Wrap.hsc:96:10: fatal error: regex.h: No such file or directory
regex-posix > compilation terminated.
regex-posix >
Progress 1/2
-- While building package regex-posix-0.96.0.0 (scroll up to its section to see the error) using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_3.2.1.0_ghc-8.10.4.exe --builddir=.stack-work\dist\274b403a build --ghc-options " -fdiagnostics-color=always"
Process exited with code: ExitFailure 1
I don't understand the initial warning. When looking at the regex-posix package's dependencies, it does list base (>=4.3 && <4.16) as a dependency, but where does the <0 come from?
I've set the resolver to LTS 18.0 in stack.yaml:
resolver: lts-18.0
According to the documentation of LTS 18.0, it uses base-4.14.1.0. If the versioning is lexicographic, I'd think that 4.14.1.0 fits the range that regex-posix requires (if we, for a moment, ignore the strange <0 constraint).
Here are the relevant parts of my package.yaml:
dependencies:
- base >= 4.7 && < 5
- regex-posix >= 0.96
library:
source-dirs: src
ghc-options:
- -Wall
My stack version:
$ stack --version
Version 2.7.1, Git revision 8afe0c2932716b0441cf4440d6942c59568b6b19 x86_64 hpack-0.34.4
I'm on Windows 10.
FWIW, it's not that I care much about regex-posix in itself. In reality, I'm trying to set up a test project, and test-framework depends on regex-posix.
How can I resolve this issue so that I can compile my code?
The error is not about the version, that is just a warning. The real error is about a missing "regex.h" header for the underlying C library. That header is almost always present on posix platforms (like linux), but not on Windows. See https://github.com/haskell-hvr/regex-posix/issues/4
Particularly this comment by Paul Johnson:
Correction to the above: you don't need mingw64. You just need to install with the _regex-posix-clib flag enabled (note the underscore).
With plain cabal: cabal install regex-posix -f _regex-posix-clib
In Stack, add the following to your stack.yaml:
extra-deps:
- regex-posix-clib-2.7
flags:
regex-posix:
_regex-posix-clib: true
In that thread there is also a comment about the <0 version: https://github.com/haskell-hvr/regex-posix/issues/4#issuecomment-699786233

undefined reference to `__gcov_exit'?

while I am building glibc library using yocto project it is giving
error: missing attribute ((constructor)) support??
after adding the coverage flags:
TARGET_CFLAGS += "-fprofile-arcs -ftest-coverage"
TARGET_LDFLAGS += "-lgcov -fprofile-arcs -ftest-coverage"
still, I am getting an error for glibc.
Please find the link of config log file : https://drive.google.com/file/d/14tiQJ8JIFE_tDWt3H9tS8zBBQROcZDNa/view
It is not working even after adding the following line in conf/local.conf :
EXTRA_OECONF = "libc_cv_ctors_header=yes"
Even i tried this
EXTRA_OECONF_append = "libc_cv_ctors_header=yes"
please find the config log file generated during compilation : https://drive.google.com/open?id=1kxTu8pt7h_9ty55OywP9Ilmmp04T61Rr
So, How to resolve this error?
Log file error Point
poky-linux/gcc/i586-poky-linux/8.2.0/ld: /tmp/ccxetEc1.o: in function `_GLOBAL__sub_D_00100_1__start':
conftest.c:(.text.exit+0x40): undefined reference to `__gcov_exit'<br>
collect2: error: ld returned 1 exit status<br>
configure:5682: $? = 1<br>
configure:5702: error: missing __attribute__ ((constructor)) support??
You are trying to build glibc with -fprofile-arcs -ftest-coverage in CFLAGS. That will not work. The errors you see are a result of these incorrect compiler flags.
A profiling glibc requires fairly substantial changes throughout the library and needs to be created by building with --enable-profile (which is not the default).
I had this error while I tried to enable coverage on a C project using a C++ test harness (CppUTest). Build system was handled by CMake.
Compilers and gcov were aligned on the same version (gcc --version, g++ --version and gcov --version gave the same version) but it seems that my build system was generated with a gcc 5 (resulting to an additional included directory by the linker: usr/lib/gcc/x86_64-linux-gnu/5). I clean the build tree and generated it again thanks to CMake which fixed the error.

Using Build-Tools (Alex) with Stack and GHCjs

I depend on a package that needs alex to build, i also need ghcjs.
When i try to run stack ghci:
language-java-0.2.8: configure (lib)
Error:
-- While building package language-java-0.2.8 using:
<long command>
Process exited with code: ExitFailure 1
Logs have been written to: /Users/LeanderK/Documents/Haskell/exemplator-java_parser/.stack-work/logs/language-java-0.2.8.log
Configuring language-java-0.2.8...
Cabal-simple_mPHDZzAJ_1.24.2.0_ghcjs-0.2.1.9007019_ghc-8.0.1: The program
'alex' version >=3.1.3 is required but it could not be found.
Warning: Build failed, but optimistically launching GHCi anyway
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: exemplator-client
Using main module: 1. Package `exemplator-client' component exe:exemplator-client-exe with main-is file: ..../app/Main.hs
Progress: 1/2<command line>: cannot satisfy -package language-java-0.2.8
(use -v for more information)
I've tried: stack build alex (just returns, don't have any output. Might work), stack install alex (doesn't work).
Output of stack install alex
Couldn't find executable alex in directory .../.stack/snapshots/x86_64-osx/lts-7.19/ghcjs-0.2.1.9007019_ghc-8.0.1/bin/
For reference: This is the cabal file of the dependency, unfortunately only found on github. This is my stack and my cabal file. There is also a reddit discussion that didn't go anywhere.

Stack setup fails with package installation errors

I'm trying to get stack running for the first time, but running stack setup in an example project (from stack new helloworld new-template) fails with the following output (I skipped the beginning, which I think was normal):
Installing library in
/home/ajl/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc7.10.2/ghc_JzwEp1oQ8kA7NFNTGk1ho5 "/home/ajl/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/bin/ghc-pkg" --force --global-package-db "/home/ajl/.stack/programs/x86_64-linux/ghc-7.10.2/lib/ghc-7.10.2/package.conf.d" update rts/dist/package.conf.install
Reading package info from "rts/dist/package.conf.install" ... done.
: Warning: Unrecognized field 420 on line 420
(Skipped unrecognized field for every line 419 down to 1)
: Warning: Unrecognized field 1 on line 1
: missing id field
: invalid package identifier:
: invalid package key:
make[1]: *** [install_packages] Error 1
make: *** [install] Error 2
Installing GHC ...%
I'm on Ubuntu 14.04, running stack 1.0.2. Not sure if it's relevant but I have ghc 7.10.1 with Cabal 1.23.0.0 installed on the system already, which work fine.
I have tried changing the resolver to older LTS versions with older ghc versions. I also tried deleting ~/.stack. Not sure what else to try given the unhelpfulness of the errors.
I figured it out. The GHC build uses grep to make packages.conf.install. I have GREP_OPTIONS=--color=auto -n set in my zsh config. The -n was putting line numbers in front of everything, which was causing the errors.
The reason I couldn't find packages.conf.install anywhere before is because it is made on the fly during GHC make. And stack does that in /tmp.

Resources