davisking / dlib

A toolkit for making real world machine learning and data analysis applications in C++
http://dlib.net
Boost Software License 1.0
13.55k stars 3.38k forks source link

Cygwin compatibility #350

Closed NiklasRosenstein closed 7 years ago

NiklasRosenstein commented 7 years ago

Hi! I am trying to compile a simple test using the dlib::config_reader in a Cygwin environment and GCC reports that readlink() and realpath() are undeclared. I was only able to fix this by add _DEFAULT_SOURCE as a preprocessor macro, which would in turn enable #define __BSD_VISIBLE 1 in <sys/features.h>.

__BSD_VISIBLE would enable readlink() in <sys/unistd.h> and realpath() in <stdlib.h>.

I wonder if this is an issue with dlib or my Cygwin environment. Does someone have insights on this topic?

NiklasRosenstein commented 7 years ago

Below the full output

niklas@DESKTOP-RQTQ13S ~/repos/craftr/examples/examples.cpp
$ craftr build
[1/4] gcc compile (/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.obj)
FAILED: /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.obj
gcc -x c++ -c /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.cpp -o /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.obj -std=c++11 -Icraftr.lib.dlib-1.0.0/data/dlib-19.2 -Wall -MD -MP -MF /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.obj.d
In file included from /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:11:0,
                 from /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.cpp:40:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h: In function ‘typename dlib::disable_if<dlib::is_std_vector<T>, void>::type dlib::directory_helper_get_files(const dlib::directory::data&, queue_of_files&)’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:376:88: error: there are no arguments to ‘readlink’ that depend on a template parameter, so a declaration of ‘readlink’ must be available [-fpermissive]
                     ssize_t temp = readlink((path+data->d_name).c_str(),buf,sizeof(buf));
                                                                                        ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:376:88: note: (if you use ‘-fpermissive’, G++ will accept your code, but allowing the use of an undeclared name is deprecated)
In file included from /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.cpp:40:0:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp: In member function ‘void dlib::file::init(const string&)’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:36:38: error: ‘realpath’ was not declared in this scope
         if (realpath(name.c_str(),buf) == 0)
                                      ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp: In member function ‘bool dlib::file::operator==(const dlib::file&) const’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:84:49: error: ‘realpath’ was not declared in this scope
         if (realpath(state.full_name.c_str(),buf) == 0)
                                                 ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:88:53: error: ‘realpath’ was not declared in this scope
         if (realpath(rhs.state.full_name.c_str(),buf) == 0)
                                                     ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp: In member function ‘void dlib::directory::init(const string&)’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:110:38: error: ‘realpath’ was not declared in this scope
         if (realpath(name.c_str(),buf) == 0)
                                      ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp: In member function ‘bool dlib::directory::operator==(const dlib::directory&) const’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:175:49: error: ‘realpath’ was not declared in this scope
         if (realpath(state.full_name.c_str(),buf) == 0)
                                                 ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:179:53: error: ‘realpath’ was not declared in this scope
         if (realpath(rhs.state.full_name.c_str(),buf) == 0)
                                                     ^
In file included from /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.cpp:11:0,
                 from /home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/all/source.cpp:40:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h: In instantiation of ‘typename dlib::disable_if<dlib::is_std_vector<T>, void>::type dlib::directory_helper_get_files(const dlib::directory::data&, queue_of_files&) [with queue_of_files = dlib::queue_kernel_c<dlib::queue_kernel_1<dlib::file, dlib::memory_manager_stateless_kernel_1<char> > >; typename dlib::disable_if<dlib::is_std_vector<T>, void>::type = void]’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:463:35:   required from ‘void dlib::directory::get_files(queue_of_files&) const [with queue_of_files = dlib::queue_kernel_c<dlib::queue_kernel_1<dlib::file, dlib::memory_manager_stateless_kernel_1<char> > >]’
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/gui_widgets/widgets.cpp:3171:32:   required from here
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:376:44: error: ‘readlink’ was not declared in this scope
                     ssize_t temp = readlink((path+data->d_name).c_str(),buf,sizeof(buf));
                                            ^
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h: In instantiation of ‘typename dlib::disable_if<dlib::is_std_vector<T>, void>::type dlib::directory_helper_get_files(const dlib::directory::data&, queue_of_files&) [with queue_of_files = dlib::queue_kernel_2<dlib::file, 20ul, dlib::memory_manager_stateless_kernel_1<char> >; typename dlib::disable_if<dlib::is_std_vector<T>, void>::type = void]’:
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:439:35:   required from ‘typename dlib::enable_if<dlib::is_std_vector<T>, void>::type dlib::directory_helper_get_files(const dlib::directory::data&, queue_of_files&) [with queue_of_files = std::vector<dlib::file>; typename dlib::enable_if<dlib::is_std_vector<T>, void>::type = void]’
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:463:35:   required from ‘void dlib::directory::get_files(queue_of_files&) const [with queue_of_files = std::vector<dlib::file>]’
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:223:34:   required from here
/home/niklas/repos/craftr/examples/examples.cpp/build/craftr.lib.dlib-1.0.0/data/dlib-19.2/dlib/dir_nav/dir_nav_kernel_2.h:376:44: error: ‘readlink’ was not declared in this scope
ninja: build stopped: subcommand failed.
davisking commented 7 years ago

What happens when you compile with cmake?

NiklasRosenstein commented 7 years ago

Should have checked CMake right way. Need to use -std=gnu++11 instead of c++11. Thanks!