Hi
I am creating programs in C++ for my Raspberry Pi Pico W on my dev machine, which is a Raspberry Pi 400 running Linux. The problem, I am going to describe is exactly the same whether I am working on a Raspberry PI OS 64 Bit Desktop or Ubuntu 22.04.3.
I am using CMAKE because I am using the Pico SDK, which is using CMAKE. I have made some of the pico-examples and a number of simple test programs. They all build without any issues.
Let me show you the CMakeLists.txt used in my test program (same as suggested by the raspberry pi organisation):
CMakeLists.txt
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(itest_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(itest
itest.cpp
)
pico_enable_stdio_usb(itest 1)
pico_enable_stdio_uart(itest 1)
pico_add_extra_outputs(itest)
target_include_directories(itest PRIVATE ${CMAKE_CURRENT_LIST_DIR} )
target_link_libraries(itest pico_cyw43_arch_lwip_threadsafe_background pico_stdlib)
So far so good. Problem is I am creating a program, where in an easy way needs to read from a file on the internet. For this purpose I need to install external libraries, such as CURL or httplib. I have tried both, none of them are working. Problem is that when I in my program writes #include <curl/curl.h>, the linker says it cannot find the file (similar for httplib). This is happeing, when I am using above CMakeList.txt.
I think I have realized though - not that it was mentioned by the Raspberry PI organisation - that when I do that, it seems to be needed to define the PATHS in CMakeLists.txt, which I the did as follows:
CMakelists.txt
cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(itest_project C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(INCLUDE_PATH "/usr/include")
include_directories(${INCLUDE_PATH})
set(INCLUDE_PATH1 "/usr/include/aarch64-linux-gnu")
include_directories(${INCLUDE_PATH1})
set(INCLUDE_PATH2 "/usr/include/aarch64-linux-gnu/bits/types")
include_directories(${INCLUDE_PATH2})
pico_sdk_init()
add_executable(itest
itest.cpp
)
pico_enable_stdio_usb(itest 1)
pico_enable_stdio_uart(itest 1)
pico_add_extra_outputs(itest)
target_include_directories(itest PRIVATE ${CMAKE_CURRENT_LIST_DIR})
#target_link_libraries(itest pico_cyw43_arch_lwip_threadsafe_background pico_stdlib libssl libcrypto)
target_link_libraries(itest pico_cyw43_arch_lwip_threadsafe_background pico_stdlib)
The includes have some effects and the linker does no longer complains about missing files, but instead it complains about really weird things:
…
Consolidate compiler generated dependencies of target itest
[ 11%] Building CXX object CMakeFiles/itest.dir/itest.cpp.obj
In file included from /usr/include/newlib/c++/10.3.1/bits/locale_facets.h:41,
from /usr/include/newlib/c++/10.3.1/bits/basic_ios.h:37,
from /usr/include/newlib/c++/10.3.1/ios:44,
from /usr/include/newlib/c++/10.3.1/ostream:38,
from /usr/include/newlib/c++/10.3.1/iostream:39,
from /home/oti/pico/itest/itest.cpp:1:
/usr/include/newlib/c++/10.3.1/arm-none-eabi/thumb/v6-m/nofp/bits/ctype_base.h:44:35: error: '_U' was not declared in this scope; did you mean '_u'?
44 | static const mask upper = _U;
| ^~
| _u
/usr/include/newlib/c++/10.3.1/arm-none-eabi/thumb/v6-m/nofp/bits/ctype_base.h:45:32: error: '_L' was not declared in this scope; did you mean '_u'?
45 | static const mask lower = _L;
| ^~
…
It goes without saying that I did not touch any of these files - and again If I remove the CMAKE paths I do not see the problem, but then the compiler cannot find curl/curl.h !!
What is going on and how do I fix it?
Your help is highly appreciated - I have spent many hours trying to get this to work…
Best regards, Ole