#compiler in vscode cant find library even though it is connected using cmake

34 messages · Page 1 of 1 (latest)

median smelt
#

i just types that fatal error: drogon/drogon.h: No such file or directory
1 | #include <drogon/drogon.h>
| ^~~~~~~~~~~~~~~~~
compilation terminated.

even though trough cmakelists main does have Drogon connected to it

add_executable(server 
    main.cc
    fetching.cc
    index.cc)
target_link_libraries(server PRIVATE Drogon::Drogon)


File in which vscode cant find drogon is main.cc
What is even more confusing to me, is that the same setup works fine in visual studio, but not vs code

pastel coralBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

tight ivy
#

Afaik Youve also gotta specify the directory where headers are located, with target_include_directories

median smelt
#

i do have specified in cmakelists

target_include_directories(server
PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR})
#

and in visual studio it worked just fine

#

same setup on my laptop with vscode also worked, but as soon as im trying to use vscode on pc it just breaks

tight ivy
#

For the Drogon, it also has includes, youve gotta put that in target_include_directories.

median smelt
#

generated cmakelists by drogon_ctl just uses

# ##############################################################################
# If you include the drogon source code locally in your project, use this method
# to add drogon 
# add_subdirectory(drogon) 
# target_link_libraries(${PROJECT_NAME} PRIVATE drogon)
#
# and comment out the following lines
find_package(Drogon CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)
#

and i have no idea what kind of directories i would need to include

tight ivy
#

Wait a sec

median smelt
#

i suspect it might be a problem with whatever json files there are in .vscode because im confused in how to use them

tight ivy
#

Youve downloaded drogon source code right?

median smelt
#

i installed it using vcpkg

tight ivy
#

Try puttin this in your cmake
include_directories(${DROGON_INCLUDE_DIRS})

median smelt
#

after copying some random launch.json
i now get this i guess

Exception has occurred: CPP/std::length_error
Unhandled exception at 0x00007FF943E0CF19 in server.exe: Microsoft C++ exception: std::length_error at memory location 0x000000BEDC70E120.
#

intellisense still thinks that drogon.h doesnt exists though

#

well, after adding include directories intellisense still cant find drogon.h

#

Im even more confused now, when i launch through f5 it gives

fatal error: drogon/drogon.h: No such file or directory
    1 | #include <drogon/drogon.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.

but when i launch through cmake tools menu it gives me this weird error

#

Absolutely confused by how vscode even works.
feels like depenging on current opened file, it just focuses strictly on this and when i try to compile using f5 it tries to compile only it.

is there a way to use only target wherever i am?

tight ivy
median smelt
#

i remember that i somehow disabled that behaivour on my laptop

tight ivy
#

Vscode is pain in the ass

median smelt
#

it is, but i have no idea of alternatives

tight ivy
#

If youre on windows, visual studio should be fine.

#

if i were to use cmake, i'd just generate and build through command line.

median smelt
#

i know, but i use linux on my laptop and fighting with vscode is just paint

median smelt
tight ivy
#

There are IDEs that integrate well with cmake on linux, like CLion and KDevelop

median smelt
#

maybe even just writing some .sh files that do everything for me, and stop caring about vscode whateverish

tight ivy
median smelt
#

idunno, just thought that it supposed to work and it doesnt, and i don't know why it doesn't work makes it feel wrong

#

i want to understand why it doesnt work, and maybe then switch to other something

median smelt
#

have no idea why it is like this still

#

!solved