vc++ and dirent.h

840 views
Skip to first unread message

DS

unread,
Feb 11, 2017, 8:21:35 AM2/11/17
to fltk.general
I'm using VC++ to building a project, and I need an open file dialog.  Just trying to add Fl_File_Chooser to my project, and I'm getting:

Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'dirent.h': No such file or directory Contacts_Fltk c:\fltk\fltk-1.3.4-1-source\fltk-1.3.4-1\fl\filename.H 101 

There is a file named that in my FL directory, but its contents are:

//
// "$Id: dirent.h 8864 2011-07-19 04:49:30Z greg.ercolano $"
//
// Directory header file for the Fast Light Tool Kit (FLTK).
//
// Copyright 1998-2011 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file.  If this
// file is missing or damaged, see the license at:
//
//     http://www.fltk.org/COPYING.php
//
// Please report all bugs and problems on the following page:
//
//     http://www.fltk.org/str.php
//

// this file is for back-compatibility only
#include "filename.H"
//
// End of "$Id: dirent.h 8864 2011-07-19 04:49:30Z greg.ercolano $".
//

This seems like some sort of loop as dirent.h is being called from filename.h.

I copied the dirent.h file from my mingw subdirectory into the FL subdirectory, and included it into my main source file with:

#include <FL/dirent.H>

and I get this:

Severity Code Description Project File Line Suppression State
Error (active)  cannot open source file "_mingw.h" Contacts_Fltk c:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\FL\dirent.h 12 

How do I get there from here?  I'm fairly new to C++ and fltk.

TIA



DS

unread,
Feb 11, 2017, 8:53:49 AM2/11/17
to fltk.general
I also added "C:\dev-cpp\include" to my c++ command line, like this:

/IC:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\;c:\dev-cpp\include\

and it still can't find _mingw.h

Someone previously told me to use double quotes around that first directory, but it worked without it.  I don't know the syntax for adding multiple include directories.

Albrecht Schlosser

unread,
Feb 11, 2017, 9:11:53 AM2/11/17
to fltkg...@googlegroups.com
On 11.02.2017 14:21 DS wrote:
> I'm using VC++ to building a project, and I need an open file dialog.

Which version of VC++ ?

> Just trying to add Fl_File_Chooser to my project, and I'm getting:
>
> Severity Code Description Project File Line Suppression State
> Error C1083 Cannot open include file: 'dirent.h': No such file or
> directory Contacts_Fltk c:\fltk\fltk-1.3.4-1-source\fltk-1.3.4-1\fl\filename.H 101

That looks wrong. It should be '...\FL\filename.H'. If you typed that
yourself, please copy'n'paste error messages in future reports
(completely). Details may matter...

Okay, how did you try to "add Fl_File_Chooser" to your project? Did you
add the file Fl_File_Chooser.cxx to your VC++ project? That would be
wrong. You should only include the header file FL/Fl_File_Chooser.H in
your source file and then use it, like so (tested under Linux only):

// Minimal File Chooser test program

#include <FL/Fl.H>
#include <FL/Fl_File_Chooser.H>

int main(int argc, char **argv) {
Fl_File_Chooser *fc = new
Fl_File_Chooser(".","*.cxx",Fl_File_Chooser::SINGLE,"Choose file");
fc->show();
return Fl::run();
}
// End of File Chooser test program

Does this work for you? Note that there is also the standard dialog
fl_file_chooser():
<http://www.fltk.org/doc-1.3/group__group__comdlg.html#ga5bc7a0eda4de38cbc33d3a16d5cfd32f>

If you don't get it working, please answer the questions above and post
a minimal, but complete (compileable) source code (like I did above).

More notes:

> There is a file named that in my FL directory, but its contents are:
> ...
> This seems like some sort of loop as dirent.h is being called from
> filename.h.

That looks strange, but please ignore this. You should certainly not use
this file directly.

> I copied the dirent.h file from my mingw subdirectory into the FL
> subdirectory, and included it into my main source file with:
>
> #include <FL/dirent.H>

Never do this! MinGW and VC++ are totally different build systems and,
as you can see, the MinGW file tries to include "_mingw.h" which is not
in your VC++ build environment:

> and I get this:
>
> Severity Code Description Project File Line Suppression State
> Error (active) cannot open source file
> "_mingw.h" Contacts_Fltk c:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\FL\dirent.h 12
>
> How do I get there from here? I'm fairly new to C++ and fltk.

Try a minimal example as given above, and if you don't get it working,
please post the example code with complete error messages. That way we
can help you best.

Welcome to the FLTK community!

DS

unread,
Feb 11, 2017, 12:17:10 PM2/11/17
to fltk.general, Albrech...@online.de
I copied and pasted the error messages.

Version is 2015 Community.

I did not "add" reference, just put #include statement.

here is the pertinent parts of my code, before I tried to start pulling in files from other places.  The dirent.h file that is in the FL directory is the one that I posted in the original post, where it just seems to be calling "filename.h" in an apparent loop.  So I have returned everything to the point where I got my original error message, and before I started trying to find a dirent.h file I could use.

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_Output.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_File_Chooser.H>


int main(int argc, char **argv)
{
 Fl_Window *window = new Fl_Window(1040, 780);
 
 
 int x = 100, y = 20, width = 350, shortw = 50, height = 20;
 int x2 = x + width + 100;
 int incr = height+5;

 Fl_Button *back = new Fl_Button(50, y + 50, shortw * 2, height * 2, "@<<");
 Fl_Button *get_file = new Fl_Button(375, y + 50, shortw * 2, height * 2, "Get File");
 Fl_Button *forward = new Fl_Button(700, y + 50, shortw * 2, height * 2, "@>>");
 window->end();
 window->show(argc, argv);
 
 return Fl::run();
}


The error messages I'm getting are:

Severity Code Description Project File Line Suppression State
Error (active)  cannot open source file "dirent.h" Contacts_Fltk c:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\FL\filename.H 101 

and

Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'dirent.h': No such file or directory Contacts_Fltk c:\fltk\fltk-1.3.4-1-source\fltk-1.3.4-1\fl\filename.H 101 

When I tried adding this line to the top of the file,  I still get similar error messages:

#include <FL/filename.H>

Severity Code Description Project File Line Suppression State
Error (active)  cannot open source file "dirent.h" Contacts_Fltk c:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\FL\filename.H 101 

Severity Code Description Project File Line Suppression State
Error C1083 Cannot open include file: 'dirent.h': No such file or directory Contacts_Fltk c:\fltk\fltk-1.3.4-1-source\fltk-1.3.4-1\fl\filename.H 101 

There is a copy of filename.h in the FL subdirectory that I have not tampered with nor copied from elsewhere.  I can include a copy of that code if helpful


Thank you.  Let me know what else I can provide.

DS

unread,
Feb 11, 2017, 12:36:21 PM2/11/17
to fltk.general
And I get the same error when using your abbreviated code, and after I add the proper include directory to C++ command line in the project properties.


On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

DS

unread,
Feb 11, 2017, 12:37:59 PM2/11/17
to fltk.general
and this looks like the same dirent.h file I have on my system, or very similar.  This is from the fltk website.



On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

Albrecht Schlosser

unread,
Feb 11, 2017, 3:32:14 PM2/11/17
to fltkg...@googlegroups.com
On 11.02.2017 18:17 DS wrote:
> I copied and pasted the error messages.

Okay, that's good.

> Version is 2015 Community.

Same here (tested now with VC++ 2015 Community, 64-bit).

> I did not "add" reference, just put #include statement.

Okay, good.
Your code worked for me in my VC++ setup, but now I think I found the
solution!

> The error messages I'm getting are:
>
> Severity Code Description Project File Line Suppression State
> Error (active) cannot open source file
> "dirent.h" Contacts_Fltk c:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\FL\filename.H 101

FLTK projects under Windows (both MinGW and Visual Studio) need a
preprocessor definition (aka macro) "WIN32" that must be defined so FLTK
"knows" it's compiled for Windows. This is somewhat "special" because
some or all Windows compilers define "_WIN32" or similar.

To confirm the issue I removed the definition of WIN32 and got similar
errors.

Now, go to your project's properties, select "C/C++" and "Preprocessor"
in the left pane and then click *ONCE* on the top row in the right pane
displaying "Preprocessor Definitions". DO NOT EDIT the string directly,
that's error prone. Instead click on the small drop down menu box at the
right border of the window that appeared when you clicked on the line.
When you click on it you'll see a menu with option "<Edit...>". Click on
that option and you'll get a new window where you can easily edit the
definitions. The same can be done for linker options, BTW. You don't
need to worry about syntax ... But don't ask me why Microsoft makes it
so difficult to _edit_ these options. :-(

Once in "Edit" mode you can add a new line in the top part of the window
with only WIN32. In my setup (generated by CMake) I have:

WIN32
_WINDOWS
_DEBUG
CMAKE_INTDIR="Debug"

As you can see, the first line is WIN32. Don't bother changing other
options unless you know you need them.

Edit your setup (add WIN32), click OK several times, and rebuild. This
should work now.

DS

unread,
Feb 12, 2017, 12:13:12 AM2/12/17
to fltk.general
Thank you, I will try that.  Would never have figured it out on my own.  The project was created as "Empty Project" (or file), and I purposely did not select a Win32 project, thinking that was what I needed to do.  Really appreciate the tip.


On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

DS

unread,
Feb 12, 2017, 12:22:03 AM2/12/17
to fltk.general
Ok, just did that, and, it seems to have gotten further, but has different errors.  I only made changes under C++/Preprocessor, not under Linker.  Wasn't sure you were telling me to do that.

These are the errors now:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: static int __cdecl Fl::run(void)" (?run@Fl@@SAHXZ) referenced in function _main Project2 c:\Users\DSNoS\OneDrive\documents\visual studio 2015\Projects\Project2\Project2\Source.obj 1 

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: __thiscall Fl_File_Chooser::Fl_File_Chooser(char const *,char const *,int,char const *)" (??0Fl_File_Chooser@@QAE@PBD0H0@Z) referenced in function _main Project2 c:\Users\DSNoS\OneDrive\documents\visual studio 2015\Projects\Project2\Project2\Source.obj 1 

Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "public: void __thiscall Fl_File_Chooser::show(void)" (?show@Fl_File_Chooser@@QAEXXZ) referenced in function _main Project2 c:\Users\DSNoS\OneDrive\documents\visual studio 2015\Projects\Project2\Project2\Source.obj 1 

Not even sure how to interpret those.  This was run on that little code snippet you sent me.

Thanks.


On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

DS

unread,
Feb 12, 2017, 12:25:39 AM2/12/17
to fltk.general
And just tried it with my original code and got just about the same errors, if not exactly the same.


On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

DS

unread,
Feb 12, 2017, 12:26:47 AM2/12/17
to fltk.general
I took out that CMAKE line, and same errors.


On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

Albrecht Schlosser

unread,
Feb 12, 2017, 5:29:19 AM2/12/17
to fltkg...@googlegroups.com
On 12.02.2017 06:22 DS wrote:
> Ok, just did that, and, it seems to have gotten further, but has
> different errors. I only made changes under C++/Preprocessor, not under
> Linker. Wasn't sure you were telling me to do that.

No, I didn't tell you that, but didn't we discuss that recently? I just
told you how to do it (by using the edit menu). See below.

> These are the errors now:
> Severity Code Description Project File Line Suppression State
> Error LNK2019 unresolved external symbol "public: static int __cdecl
> Fl::run(void)" (?run@Fl@@SAHXZ) referenced in function
> _main Project2 c:\Users\DSNoS\OneDrive\documents\visual studio
> 2015\Projects\Project2\Project2\Source.obj 1

This tells you that the linker could not find the FLTK lib (Fl::run()),
the other errors were similar (about Fl_File_Chooser).

What you need is documented in the chapter "FLTK Basics":
http://www.fltk.org/doc-1.3/basics.html#basics_visual_cpp

"In Visual C++ you will need to tell the compiler where to find the FLTK
header files. This can be done by selecting "Settings" from the
"Project" menu and then changing the "Preprocessor" settings under the
"C/C++" tab. You will also need to add the FLTK (FLTK.LIB or FLTKD.LIB)
and the Windows Common Controls (COMCTL32.LIB) libraries to the "Link"
settings. You must also define WIN32.

More information can be found in README.MSWindows.txt."

Please take a look at README.MSWindows.txt, chapter "Creating new Projects":

Create a new project of type "General", "Empty Project" and add a simple
"C++" file to it. The FLTK "hello" source code is a good base.

Now open the Project Properties dialog and add "Comctl32.lib" and all
the FLTK libraries that you want to use (at least "fltk.lib") to
Additional Dependencies (Configuration Properties > Linker > Additional
Dependencies). In the same dialog, add "WIN32" to the C++ Preprocessor
Definitions (Configuration Properties > C/C++ > Preprocessor >
Preprocessor Definitions).


Note: there are more instructions worth to take a look at. The
instructions above don't show the hint I gave you before to click once
on the option field and use the '<Edit...>' menu, but that was likely
not available in this form in the older VC++ version the docs are based on.

So, to sum it up: you added the WIN32 define, but you still need to add
the FLTK lib (fltk.lib or fltkd.lib) and comctl32.lib to the linker
settings. You may need to use the full path for fltk.lib or add, as
Nikita wrote:

Linker=>General=>Additional Library Directories :
C:\FLTK\fltk-1.3.4-1-source\fltk-1.3.4-1\lib

That would add the path so you can just use 'fltk.lib'.


DS

unread,
Feb 12, 2017, 8:12:05 AM2/12/17
to fltk.general
Hmmm....ok.  I had some settings filled in on the linker, and my other code was compiling, and not the other code is not, so I lost a setting somehow. 

THanks.  I'll double  back and try to fix it.


On Saturday, February 11, 2017 at 5:21:35 AM UTC-8, DS wrote:

DS

unread,
Feb 12, 2017, 8:38:31 AM2/12/17
to fltk.general
Ok, got it working.  Had to move my linker directives from command line to additional dependencies.  Thanks for the tips.

Not sure why it quit working, as I don't remember changing that.
Reply all
Reply to author
Forward
0 new messages