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

c++: error: '-march=native': ISA string must begin with rv32 or rv64 #105

Closed
marklove5102 opened this issue Jan 2, 2024 · 5 comments
Closed
Labels
architecture-compat Compatibility with non-x64 architecture compiler-compat Compatibility with compilers

Comments

@marklove5102
Copy link

marklove5102 commented Jan 2, 2024

我认为最少要像

https://github.com/StanfordLegion/legion/blob/f7d3bbe27c994879528c4a7b0e19cd09bea29daf/CMakeLists.txt#L153
这样写才合理吧
不然riscv下编译不认

target_compile_options(co_context PUBLIC -march=native)

的-march=native

环境 真机ubuntu

make@make:~/ubuntu$ uname -m
x86_64

make@make:~/ubuntu$ uname -a

Linux make 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

make@make:~/ubuntu$ 

docker riscv64

docker run -it -v /usr/bin/qemu-riscv64-static:/usr/bin/qemu-riscv64-static riscv64/ubuntu:23.04 /bin/bash


编译报错

root@53454d58d5b4:/# cd co_context
root@53454d58d5b4:/co_context# ls
CMakeLists.txt  CMakePresets.json  LICENSE  README.md  b  cmake  doc  example  extern  format_count.sh  include  lib  test
root@53454d58d5b4:/co_context# rm -rf b
root@53454d58d5b4:/co_context# ls
CMakeLists.txt  CMakePresets.json  LICENSE  README.md  cmake  doc  example  extern  format_count.sh  include  lib  test
root@53454d58d5b4:/co_context# mkdir b
root@53454d58d5b4:/co_context# cd b
root@53454d58d5b4:/co_context/b# cmake ..
-- The CXX compiler identification is GNU 12.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- target_kernel_version = 5.15.0-91-generic
-- LIBURINGCXX_KERNEL_VERSION_MAJOR = 5
-- LIBURINGCXX_KERNEL_VERSION_MINOR = 15
-- Performing Test LIBURINGCXX_HAS_KERNEL_RWF_T
-- Performing Test LIBURINGCXX_HAS_KERNEL_RWF_T - Success
-- Performing Test LIBURINGCXX_HAS_TIME_TYPES
-- Performing Test LIBURINGCXX_HAS_TIME_TYPES - Success
-- Performing Test LIBURINGCXX_HAS_OPENAT2
-- Performing Test LIBURINGCXX_HAS_OPENAT2 - Success
Setting default CMAKE_BUILD_TYPE to Release
CMake Warning at cmake/CompileOption.cmake:43 (message):
  mimalloc disabled
Call Stack (most recent call first):
  CMakeLists.txt:21 (include)


-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /co_context/b

root@53454d58d5b4:/co_context/b# uname -m
riscv64
root@53454d58d5b4:/co_context/b# uname -a
Linux 53454d58d5b4 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux


root@53454d58d5b4:/co_context/b# make -j4
[  1%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/condition_variable.cpp.o
[  3%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/semaphore.cpp.o
[  5%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/mutex.cpp.o
[  7%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/spin_mutex.cpp.o
c++: error: '-march=': ISA string must begin with rv32 or rv64
c++: error: '-march=native': ISA string must begin with rv32 or rv64
make[2]: *** [CMakeFiles/co_context.dir/build.make:76: CMakeFiles/co_context.dir/lib/co_context/co/condition_variable.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/co_context.dir/build.make:104: CMakeFiles/co_context.dir/lib/co_context/co/semaphore.cpp.o] Error 1
c++: error: '-march=native': ISA string must begin with rv32 or rv64
c++: error: '-march=native': ISA string must begin with rv32 or rv64
make[2]: *** [CMakeFiles/co_context.dir/build.make:90: CMakeFiles/co_context.dir/lib/co_context/co/mutex.cpp.o] Error 1
make[2]: *** [CMakeFiles/co_context.dir/build.make:118: CMakeFiles/co_context.dir/lib/co_context/co/spin_mutex.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:191: CMakeFiles/co_context.dir/all] Error 2
make: *** [Makefile:136: all] Error 2
root@53454d58d5b4:/co_context/b# 
@marklove5102
Copy link
Author

marklove5102 commented Jan 2, 2024

第二次编译遇到的问题

root@53454d58d5b4:/co_context/b# make -j4
[  1%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/spin_mutex.cpp.o
[  5%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/condition_variable.cpp.o
[  7%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/mutex.cpp.o
[  7%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/co/semaphore.cpp.o
[  9%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/detail/worker_meta.cpp.o
[ 13%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/io_context.cpp.o
[ 13%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/net/inet_address.cpp.o
[ 15%] Building CXX object CMakeFiles/co_context.dir/lib/co_context/net/socket.cpp.o
[ 17%] Linking CXX static library libco_context.a
[ 17%] Built target co_context
[ 19%] Building CXX object example/CMakeFiles/cv_notify_one.dir/cv_notify_one.cpp.o
[ 21%] Building CXX object example/CMakeFiles/channel.dir/channel.cpp.o
[ 23%] Building CXX object example/CMakeFiles/cancel_io.dir/cancel_io.cpp.o
[ 25%] Building CXX object example/CMakeFiles/cv_notify_all.dir/cv_notify_all.cpp.o
[ 27%] Linking CXX executable cv_notify_one
[ 29%] Linking CXX executable cancel_io
[ 31%] Linking CXX executable channel
[ 33%] Linking CXX executable cv_notify_all
/usr/bin/ld: /tmp/ccs8iKnY.ltrans0.ltrans.o: in function `.L0 ':
<artificial>:(.text+0x1a66): undefined reference to `__atomic_exchange_1'
/usr/bin/ld: <artificial>:(.text+0x1b0c): undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
make[2]: *** [example/CMakeFiles/cv_notify_one.dir/build.make:98: example/cv_notify_one] Error 1
make[1]: *** [CMakeFiles/Makefile2:321: example/CMakeFiles/cv_notify_one.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
/usr/bin/ld: /tmp/ccIttIB9.ltrans0.ltrans.o: in function `.L0 ':
<artificial>:(.text+0xa96): undefined reference to `__atomic_exchange_1'
/usr/bin/ld: <artificial>:(.text+0xb28): undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
make[2]: *** [example/CMakeFiles/cancel_io.dir/build.make:98: example/cancel_io] Error 1
make[1]: *** [CMakeFiles/Makefile2:243: example/CMakeFiles/cancel_io.dir/all] Error 2
/usr/bin/ld: /tmp/ccSpZeS7.ltrans0.ltrans.o: in function `.L175':
<artificial>:(.text+0xaa0): undefined reference to `__atomic_exchange_1'
/usr/bin/ld: /tmp/ccSpZeS7.ltrans0.ltrans.o: in function `.L196':
<artificial>:(.text+0xb32): undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
make[2]: *** [example/CMakeFiles/channel.dir/build.make:98: example/channel] Error 1
make[1]: *** [CMakeFiles/Makefile2:269: example/CMakeFiles/channel.dir/all] Error 2
/usr/bin/ld: /tmp/ccuLTVSb.ltrans0.ltrans.o: in function `.L459':
<artificial>:(.text+0x1cc2): undefined reference to `__atomic_exchange_1'
collect2: error: ld returned 1 exit status
make[2]: *** [example/CMakeFiles/cv_notify_all.dir/build.make:98: example/cv_notify_all] Error 1
make[1]: *** [CMakeFiles/Makefile2:295: example/CMakeFiles/cv_notify_all.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

大概找了下解决方案
advancedtelematic/aktualizr#1427
android/ndk#10

我只是体验下riscv 开发。

@marklove5102
Copy link
Author

marklove5102 commented Jan 3, 2024


target_link_libraries(co_context PUBLIC Threads::Threads)

添加
atomic

target_link_libraries(co_context PUBLIC Threads::Threads atomic)

编译通过

root@53454d58d5b4:/app/co_context/b# make -j4
[ 17%] Built target co_context
[ 21%] Linking CXX executable cancel_io
[ 21%] Linking CXX executable cv_notify_all
[ 23%] Linking CXX executable channel
[ 25%] Linking CXX executable cv_notify_one
[ 27%] Built target cv_notify_all
[ 29%] Building CXX object example/CMakeFiles/echo_server.dir/echo_server.cpp.o
[ 31%] Built target cv_notify_one
[ 33%] Building CXX object example/CMakeFiles/echo_server_MT.dir/echo_server_MT.cpp.o
[ 35%] Built target cancel_io
[ 37%] Building CXX object example/CMakeFiles/iota.dir/iota.cpp.o
[ 39%] Built target channel
[ 41%] Building CXX object example/CMakeFiles/multi_fan_out.dir/multi_fan_out.cpp.o
[ 43%] Linking CXX executable iota
[ 43%] Built target iota
[ 45%] Linking CXX executable echo_server
[ 47%] Building CXX object example/CMakeFiles/mutex.dir/mutex.cpp.o
[ 49%] Linking CXX executable echo_server_MT
[ 50%] Linking CXX executable multi_fan_out
[ 50%] Built target echo_server
[ 52%] Building CXX object example/CMakeFiles/netcat.dir/netcat.cpp.o
[ 52%] Built target echo_server_MT
[ 54%] Building CXX object example/CMakeFiles/netcat_timeout.dir/netcat_timeout.cpp.o
[ 54%] Built target multi_fan_out
[ 56%] Building CXX object example/CMakeFiles/redis_echo.dir/redis_echo.cpp.o
[ 58%] Linking CXX executable mutex
[ 58%] Built target mutex
[ 60%] Building CXX object example/CMakeFiles/redis_echo_MT.dir/redis_echo_MT.cpp.o
[ 62%] Linking CXX executable netcat
[ 64%] Linking CXX executable netcat_timeout
[ 66%] Linking CXX executable redis_echo
[ 66%] Built target netcat
[ 68%] Building CXX object example/CMakeFiles/resume_on.dir/resume_on.cpp.o
[ 68%] Built target netcat_timeout
[ 70%] Building CXX object example/CMakeFiles/sem.dir/sem.cpp.o
[ 70%] Built target redis_echo
[ 72%] Building CXX object example/CMakeFiles/sem_std.dir/sem_std.cpp.o
[ 74%] Linking CXX executable redis_echo_MT
[ 74%] Built target redis_echo_MT
[ 76%] Building CXX object example/CMakeFiles/stop_token.dir/stop_token.cpp.o
[ 78%] Linking CXX executable resume_on
[ 80%] Linking CXX executable sem_std
[ 82%] Linking CXX executable sem
[ 82%] Built target resume_on
[ 84%] Building CXX object example/CMakeFiles/timer.dir/timer.cpp.o
[ 84%] Built target sem_std
[ 86%] Building CXX object example/CMakeFiles/when_all.dir/when_all.cpp.o
[ 86%] Built target sem
[ 88%] Linking CXX executable stop_token
[ 90%] Building CXX object example/CMakeFiles/when_any.dir/when_any.cpp.o
[ 90%] Built target stop_token
[ 92%] Building CXX object example/CMakeFiles/when_some.dir/when_some.cpp.o
[ 94%] Linking CXX executable timer
[ 96%] Linking CXX executable when_all
[ 96%] Built target timer
[ 98%] Linking CXX executable when_any
[ 98%] Built target when_all
[100%] Linking CXX executable when_some
[100%] Built target when_any
[100%] Built target when_some
root@53454d58d5b4:/app/co_context/b# ls
CMakeCache.txt  CMakeFiles  Makefile  cmake_install.cmake  co_context-config-version.cmake  co_context-config.cmake  example  extern  lib  libco_context.a
root@53454d58d5b4:/app/co_context/b# cd example
root@53454d58d5b4:/app/co_context/b/example# ls
CMakeFiles  cancel_io  cmake_install.cmake  cv_notify_one  echo_server_MT  multi_fan_out  netcat          redis_echo     resume_on  sem_std     timer     when_any
Makefile    channel    cv_notify_all        echo_server    iota            mutex          netcat_timeout  redis_echo_MT  sem        stop_token  when_all  when_some
root@53454d58d5b4:/app/co_context/b/example# cancel_io
bash: cancel_io: command not found
root@53454d58d5b4:/app/co_context/b/example# ./cancel_io
terminate called after throwing an instance of 'std::system_error'
  what():  uring()::__sys_io_uring_setup: Function not implemented
Aborted (core dumped)
root@53454d58d5b4:/app/co_context/b/example# ./
bash: ./: Is a directory
root@53454d58d5b4:/app/co_context/b/example# ./channel
terminate called recursively
terminate called recursively
terminate called recursively
Aborted (core dumped)
root@53454d58d5b4:/app/co_context/b/example# ./cv_notify_all
terminate called after throwing an instance of 'std::system_error'
  what():  uring()::__sys_io_uring_setup: Function not implemented
Aborted (core dumped)

docker信息

root@53454d58d5b4:/app/co_context/cmake# uname -m
riscv64
root@53454d58d5b4:/app/co_context/cmake# uname -a
Linux 53454d58d5b4 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 riscv64 riscv64 riscv64 GNU/Linux

好吧是时候,结束体验。

@Codesire-Deng
Copy link
Owner

Codesire-Deng commented Jan 3, 2024

牛逼👍
看来 riscv 还需要额外的系统调用支持。

@Codesire-Deng
Copy link
Owner

我想问下如果要复现你的环境,需要哪些工具,能否给些关键词?

@Codesire-Deng Codesire-Deng added compiler-compat Compatibility with compilers architecture-compat Compatibility with non-x64 architecture labels Jan 3, 2024
@marklove5102
Copy link
Author

marklove5102 commented Jan 3, 2024

riscv64 docker可以使用服务器的所有CPU

docker 执行
docker run -it -v /usr/bin/qemu-riscv64-static:/usr/bin/qemu-riscv64-static riscv64/ubuntu:23.04 /bin/bash
如果 上面语句exit了

docker container ls -a
找到这个容器的id
执行进入容器bash环境
docker exec -it 容器id bash
如果重启了没设置常驻后台开机自启
启动容器 再进入bash环境
docker start 容器id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture-compat Compatibility with non-x64 architecture compiler-compat Compatibility with compilers
Projects
None yet
Development

No branches or pull requests

2 participants