6

I've been trying to get my cmake project set up with HDF5 on Windows 10 (64bit), using the CLion editor and MinGW. After a ton of time trying to get my CMakeLists file set up properly, I got something working - the code compiles, no errors from mingw32-make or from cmake. However, I'm still getting red underlined errors in CLion, which don't seem to have any impact on the build, but I have a feeling that they're there because I did something incorrect. (I'm very new doing anything more than class projects with C++)

Here is my CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

project(testProject)
add_definitions(-std=c++11)
set(SOURCE_FILES hdf_example.cpp)

link_libraries("C:/Program Files/HDF_Group/HDF5/1.8.16/lib/hdf5_hl_cpp-shared.lib"
               "C:/Program Files/HDF_Group/HDF5/1.8.16/lib/hdf5_cpp-shared.lib"
               "C:/Program Files/HDF_Group/HDF5/1.8.16/lib/hdf5-shared.lib")

add_executable (abc hdf_example.cpp)

enter image description here

Compiling this from the command line using mingw32-make or in the IDE both result a successful compilation with no errors or warnings that I can see.

C:\Users\Me\Documents\project_name\temp-build\src\abc>mingw32-make
[ 50%] Building CXX object src/s3/CMakeFiles/abc.dir/hdf_example.cpp.obj
[100%] Linking CXX executable abc.exe
[100%] Built target abc

Is this something I should be concerned about? Or should I just ignore it since everything compiles?

Barmar
  • 741,623
  • 53
  • 500
  • 612
TomW
  • 83
  • 1
  • 7
  • What about repeating the build in the terminal/cmd? Make a `build` dir somewhere, type `cmake path_to_source` and then `make` – Severin Pappadeux Jan 29 '16 at 22:44
  • I've done that - no warnings or errors. Both with manually using cmake and by pressing the run button in CLion I can compile and run without issue, it's just the editor view in CLion that thinks there's an issue – TomW Jan 30 '16 at 23:52

3 Answers3

5

I had this problem and solved it by placing #include <getopt.h> above #include <unistd.h> in the C file. This could be viewed as a bug in CLion. I have created an issue for this. The workaround for now is to rearrange your imports.

For details you can also read my question about this.

Instantiating an unknown structure without a reference

enter image description here

Community
  • 1
  • 1
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
3

Your IDE and building tools are two "completely" different processes. You have nothing to worry about if your code compiles with Cmake and MingW. You probably have configured your IDE with different settings than given in your CMakeLists. You need to link the hdf5 C++ library in your editor to solve the "problems" in your IDE. This will only improve readability.

thburghout
  • 27
  • 5
  • The IDE is using mingw and the CMakeLists file to compile the code, and its configured to use the same mingw and cmake as with command line. – TomW Jan 28 '16 at 16:42
  • 1
    Building and syntax checking in the IDE are 2 separate things. MinGW itself doesn't give you a nice list of places to underline, it just reports *some* build errors (the first ones it encounters). On the other hand, the IDE needs to undeline as much errors as possible, so it uses its own (hand-crafted) parser and sort-of-compiler to just do the syntax checking. This is why, even with MinGW configured in the IDE, it still shows errors MinGW accepts. – Martin Pecka Feb 22 '16 at 15:22
  • also you should search clion tracker for this error and make a bug-report if you don't find similar issues – strangeqargo Apr 25 '16 at 21:24
0

I also encountered this error and it turns out that in my case I actually forgot to include a header. Using Emacs the correct error information (Implicit instantiation of undefined template 'std::basic_ifstream<char,std::char_traits<char>>') is shown (See Why am I getting this ifstream error?). I'm not sure why CLion reported the error incorrectly.

xji
  • 7,341
  • 4
  • 40
  • 61