VisualDGCmake with environment variable

Sysprogs forums Forums VisualGDB VisualDGCmake with environment variable

This topic contains 15 replies, has 2 voices, and was last updated by  roy111 3 months ago.

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #20317

    roy111
    Participant

    Hi,

    I’m trying to build a CMake project on an Ubuntu machine from VisualDGB on windows (source, gcc toolchain and build output are on Ubuntu).

    The CMake file includes system environment variables, for instance:

    include_directories (“$ENV{OPENCV_SRC_DIR}/include”)

    Where the syntax $ENV{…} allows to use an Ubuntu’s system environment variables within the CMake file.

    It works fine when I manually run cmake… make … from the Ubuntu machine, however when I use VisualGDB from the windows machine to build on the Linux Machine (source is on the Linux)

    then the environment variables become empty strings.

    Any idea on how to use VisualGDB with CMake file which include system environment variables, using the $ENV{variable_name} syntax?

    Thanks !

    #20323

    support
    Keymaster

    Hi,

    This would happen for environment variables that are only set for interactive shells. We actually have a detailed page describing this (and known workarounds) here: http://visualgdb.com/support/fixenv/

    If it doesn’t help, please let us know and we will investigate this further.

    #20384

    roy111
    Participant

    Hi,

    Could not make it work.  Regarding the solution mentioned in the link found in the answer above ( http://visualgdb.com/support/fixenv/ )

    1. I could not get to the screen which warns about “Mismatching environment detected”.  I remember I’ve seen it once, but it doesn’t reappear, even if I create new project, and clean caches, reload CMake project.
    2. In the “SSH Manager” on tab “Host-wide Settings” I get an empty white text square, and not the one shown in the above link with “Extra Environments” text line and more.
    3. It is not clear to me: If I will eventually manage to get to the above message and/or text screen, should I choose the “fix” option or fill all the extra environment variables manually myself?

    Thanks!

    #20387

    support
    Keymaster

    Hi,

    No problem, we can help you pinpoint this. First of all, please try narrowing this down to one specific variable and a specific context. E.g. try creating a custom project where the build command will be just “echo $OPENCV_SRC_DIR”. Can you confirm that it doesn’t work when launched via VisualGDB, but works manually?

    Regarding the environment fix, VisualGDB normally checks for mismatching environment each time you create a project, and then can either remember correct the per-host settings (will be shown in the SSH Manager), or add the mismatching variables to the ignore list (under Tools->Options->VisualGDB). Normally it should work intuitively, but if your variables are defined in a way that prevents VisualGDB from getting them, it might get confusing. Please try checking the variable manually as described above to narrow it down and we will help you configure VisualGDB to handle this automatically.

    #20459

    roy111
    Participant

    Hi,

    I managed to go around the environment problem by manually defining all the environment variables in the CMake file. The project now builds and runs well both manually (from Ubuntu console) and by using VisualGDB on Linux. I can even add break points and view their values !

    But now, the intelli-sense and auto complete do not work at all. (I verified that I’m using the correct keyboard shortcut: Ctrl+Space).

    Just a reminder: My source code is on the linux machine (mounted from the windows, but available to VisualGDB only from Linux).

    I attached an image with the VisualGDB intellisense screen.

    Thanks!

     

     

    Attachments:
    You must be logged in to view attached files.
    #20465

    support
    Keymaster

    Hi,

    Please try reloading the remote directories on the “IntelliSense Directories” page (not IntelliSense Settings). If this doesn’t help, please locate a specific header file that is not found and check if its directory is listed under Clang IntelliSense Diagnostics Console -> Project View->Default CFLAGS (the corresponding command-line option should look like -I<directory>).

    #20467

    roy111
    Participant

    Doesn’t work:

    1. For some reasons all my libraries which are includes in the CMake project using add_subdirectory(…) where not added to the “IntelliSense Directories”. Only after I added them explicitly into the CMake using “include_directories(…) “ IntelliSense Directories”, and I verified that the .cpp and .h files were added to the local cache (on windows), using the path indicated in the “IntelliSense Directories” screen. Note that the project builds properly using VisualGDB, run, and stop at breakpoint without adding those additional “include_directories(…) “ commands).
    2. Even after adding the “include_directories(…) “, and even thought all the .h and .cpp files are included in the local cache, autocompletion and intellisense find functionality (go to definition, go to declaration…) doen’t even try to find anything nor autocomplete the names.
    3. Even a local integer variable is not auto-completed when i try to use it just a line below where it is declared in a .cpp file.

    Any ideas ?

    #20468

    roy111
    Participant

    Also, in addition to the above message, I could not find the view->Default CFLAGS.

    In the VisualStudio I opened “View” –> “CLang IntelliSense Status” which opened a window called “Clang IntelliSense Diagnostics Console”, and when I click on the “Projects” I get a long list of the project’s file, where the “.cpp” files are next to a wheel icon and the “.h” files are are next to a red “X” icon (is that bad ???), but no CFLAGS are found.

    #20473

    support
    Keymaster

    Hi,

    The add_subdirectory() command should not normally affect the include directories, it only tells CMake to look for CMakeLists.txt in a specified location.

    The behavior you are describing might also be caused by disabled “aggressive completion” mode. If auto-completion works when you press Ctrl-Space, please click at the lightning icon symbol in the completion popup to enable the aggressive mode.

    Unfortunately it’s hard to say what is going on with the diagnostics console without a screenshot. If you could attach one, we could help you fix this.

    #20482

    roy111
    Participant

    Hi,

    1. I attached two screenshots of intellisense options and CLang disgnostics console. (I blacked out names of files in order to maintain company’s propriety)
    2. I could not find the “agressive mode” checkbox.
    3. When I click Ctl+Space NOTHING happens. No popup, no icon, no intellisense lighting icon.
    4. Please note that the files structures is as follows:
      1. Windows folder with CMake root and source files are mounted into the Linux machine (I build inside a docker, but that should not be different than a regular Linux guest on top ov VBox). Build, run, stopping at break points using VisualGDB works well.
      2. The intellisense source files (.cpp and .h) are cached by VisualGDB on the host.
      3. For some reason Intellisense does not even respond to “Ctrl+Space”. 
    Attachments:
    You must be logged in to view attached files.
    #20485

    roy111
    Participant

    In addition to the above message and screen captures, the problem may be related to a bigger issue: The search utility does not work !!! Edit->Find and replace -> Find in files (search in entire solution) does not seem to find anything outside the current open file. There seems to be a major issue with the CMake file and source files located on the Ubuntu docker machine (mounted into the docker machine from the windows host).

    #20486

    roy111
    Participant

    Found something which may shed some light on the problem: Whenever I reload the CMake file into the VisualGDB project, I get an error about missing files. (See attached screen capture of the error).

    It turns out that those are files indirectly required required by an included path of a library called Eigen. Now, whenever I comment out that included library path the intellisense starts to work (searching for a function name in the entire solution still does not work). However I cannot build the project without that library.

    So, I need to comment out that include of that library in CMake in order to get intellisense, and to uncomment it in order to build and run.

    Any way to tell Intellisense to ignore a few missing files and make use of the rest ? Any other solution ? (See also the above two comments with screen shots representing the problem)

    Thanks.

    Attachments:
    You must be logged in to view attached files.
    #20490

    support
    Keymaster

    Hi,

    First of all, sorry about the broken ‘find all’ function. The internal VS implementation of this function is hardcoded to use files on the Windows machine only, so it indeed doesn’t work with projects accessed fully via SSH yet (we will eventually provide our own equivalent of this function). The “find all references”, code map and other functions should work as expected though.

    With eigen, please try locating a specific .cpp file that shows the missing header files, locate it in the IntelliSense Diagnostics Console -> Project View  and click on it (the gear icon means that the file has overridden build arguments, the “X” icon means that the file does not participate in build and doesn’t indicate an error). Once you click at that file, VisualGDB will display the CFLAGS used for that file at the bottom of the diagnostics console window.

    Please check if the CFLAGS shown there mention the directory where the missing headers are located. If you are not sure, please let us know the details (full directory path and exact CFLAGS).

    #20497

    roy111
    Participant

    Hi,

    Based on the above reply I moved the source from the guest Ubuntu to the host Windows. As a result I can now build, run, debug, and search for functions in the entire solution.

    When I right click the mouse and search for a function definition, then sometimes the CLang intellisense crash, but it’s not a show stopper and I can keep working while having most of the benefits of VisualGDB.

     

    After moving the source to the Windows host, for some reason the application fails to open a window (using OpenCV’s imshow(…) function).

    The window does open properly if I run the application from a command line from a console within the Ubuntu host.

    The message I get is:

    (process:3762): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback ‘C’ locale.
    (input preprocessed image:3762): Gtk-WARNING **: cannot open display:

    Any ideas? Why does the window fail to open when I run it from VisualGDB on windows but works OK when I run from a command line from within the Ubuntu ?

    Thanks!

     

    #20528

    support
    Keymaster

    Hi,

    Perhaps you have accidentally disabled X11 forwarding? Please double-check that the Program output setting (bottom of the Debug Settings page of VisualGDB Project Properties). Does it state “Forward program output to Visual Studio”? If yes, please also check that X11 forwarding is not disabled via Tools->VisualGDB->SSH Host Manager->Per-host Settings.

Viewing 15 posts - 1 through 15 (of 16 total)

You must be logged in to reply to this topic.