Having trouble with file includes

Sysprogs forums Forums VisualGDB Having trouble with file includes

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #646
    Anonymous
    Participant

    Hello,

    I’m currently evaluating VisualGDB for use with an STM32 on a custom built board. I’ve spent several months developing a code base in another program, so I already have a large project with an established file structure. I’d like to keep this structure as I move to VGDB, but I am getting a lot of errors such as “error: xxx.h: No such file or directory.” It looks like the way to get rid of this is by explicitly writing out file paths in my include statements. Instead of #include “file.h”, I’d have to write #include “/../../folder1/folder2/file.h” This seems unnecessarily complicated. My project uses the LwIP library, which is a large package in itself, one which I shouldn’t have to modify to compile properly. Is there some way to make VS or VGDB figure out these file paths automatically?

    Thanks

    #2642
    ket
    Participant

    Hi,

    If the errors you are getting are compilation errors, then you need to add include directories. If you are using VisualGDB makefiles, then simply go to VisualGDB Project Properties and add the include directories(the directories your files are directly in) to the include directories list in the makefile settings. If you are using your own makefiles, then you need to add the equivalent -I statements to your build recipes.

    If the errors are Visual Studio IntelliSense errors, then again go to VisualGDB Project Properties and add the directories to the IntelliSense directories list. If you are using VisualGDB makefiles, then all include directories are added to IntelliSense directories automatically.

    #2643
    Anonymous
    Participant

    Thanks ket, adding the folders to the include directories is the way to fix this issue. Unfortunately, I’d have to add every single folder in my project to this list, which seems ridiculous. Is there any way to include one base directory and recursively search for and include all sub-directories? Am I violating some basic coding practice by logically separating my files into folders? It works as expected with the IDE I currently use. Not sure why it wouldn’t work here.

    Thanks

    #2644
    ket
    Participant

    Hi,

    gcc does not support recursive include directories. The point about include paths is to be able to pick and choose which directories to include. Your current IDE is probably adding all the subfolders to includes automatically.

    There is nothing wrong with separating files into folders, it only means that you either need to refer to them based on their relative paths or add the folder paths to include directories. The usual point about making subfolders for code is to be able to include only partial subsets for compilation to reduce compile time for some targets. If many subfolders of headers need to be included, then there is usually a master header file to include instead which in turn refers to all the headers in their subdirectories. For Visual Studio c/c++ projects creating actual subfolders to sort the code for more convenient development is not necessary as the folders in Solution Explorer are virtual anyway and you can create as many virtual folders as you want while still having all the code in one physical folder. You can switch viewing modes in Solution Explorer by enabling and disabling the “Show All Files” button at the top.

    #2649
    Dan
    Participant

    Since it is not using the user property page for the include and source directories, I added my extra includes (for the USB OTG driver of the STM32 familiy) in the project property page as follow:
    Include Directories:
    $(ProjectDir)STM32_USB_OTG_Driverinc
    $(ProjectDir)STM32_USB_Device_LibraryCoreinc
    $(ProjectDir)STM32_USB_Device_LibraryClasscdcinc

    Source Directories
    $(ProjectDir)STM32_USB_OTG_Driversrc
    $(ProjectDir)STM32_USB_Device_LibraryCoresrc
    $(ProjectDir)STM32_USB_Device_LibraryClasscdcsrc

    It compiles and builds without a glitch, but should I use the VisualGDB project property pages instead of the general VisualStudio project property page ?

    Also, is there a way to configure the GNUC as C and not C++ (i.e.: undefine _cplusplus) ?

    #2646
    ket
    Participant

    Hi,

    Normally you should only edit settings in VisualGDB Project Properties. If you edit settings on the Makefile settings page your changes will be saved into the Makefile and the settings tested. By adding include directories there, also IntelliSense directories get set properly. To include source just add it to the project.

    Visual Studio specifies the __cplusplus flag in IntelliSense. Add a a work-around to your main header file or each source file as follows:

    #ifdef _MSC_VER
    #undef __cplusplus
    #endif
    #2647
    Dan
    Participant

    Adding:
    #ifdef _MSC_VER
    #undef __cplusplus
    #endif
    worked perfectly, thanks for the help !

    #2648
    Dan
    Participant

    Ok I moved the Include files project properties from Visual Studio project properties page to VisualGDB project properties page like you suggested, but it doesn’t work anymore (well with the IntelliSense as I am not build the whole project since I’m still in the process of merging files).
    Posting pictures of both methods (of course only one method is used at a time):
    (works)

    VS

    (doesn’t work)

    Do I have to update the IntelliSense directories too ? If so, shouldn’t it be done automatically ? And why doesn’t it allow to use the macro $(ProjectDir) on the IntelliSense directories page ?

    #2645
    ket
    Participant

    Hi,

    For the include directories you do not need to specify $(ProjectDir), the subdirectory names are enough. Everything in Makefile settings gets put into the Makefile, so using macros there will not work as make will not be able to translate them (unless they are environment variables that are also passed to make). The include directories should be updated automatically based on the include directories, unless the toolchain test fails and the new settings are not committed.

    Currently, the IntelliSense directories page allows entering directories only. Entering paths containing macros directly to IntelliSense could work. We will consider adding support to macros also from the IntelliSense directories page, at least in the case of local IntelliSense directories.

    #2650
    Dan
    Participant

    Ok cool, I can do almost everthing I require with your tool. Since I am still evaluating the decision to use it that’d be swell to include the changes to the IntelliSense directories page to allow macros soon 🙂

    Anyhow, great tool so far, keep up the good work !

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.