64-bit gcc-4.6 Ubuntu12.04 fltk-1.1.10-sourceのコンパイルに成功した.tar.gz


2日間悩んだバグがやっと解決!プログラムが必要なので、このバージョンを使用する必要があります.探索を経て、このバグはこのように簡単に解決することができます!本文はソースコードがfltk-1.1.10のステップをインストールすることを記載して、誤り、解決方法と誤りの背後に隠れている原理!
インストール手順:
公式サイトからダウンロードしたソースパッケージfltk-1.1.10-sourceを解凍します.tar.gz、/usr/local/src/ディレクトリの下に置く
sudo tar -xvf fltk-1.1.10-source.tar.gz

cd fltk-1.1.10

sudo mkdir bin

cd bin

sudo ccmake ../

cmakeの構成:
BUILD_EXAMPLES                    *ON   
BUILD_SHARED_LIBS              *OFF
BUILD_TESTING                    *ON   
CMAKE_BACKWARDS_COMPATIBILITY   *2.4                                            
CMAKE_BUILD_TYPE               *   
CMAKE_INSTALL_PREFIX           */usr/local/fltk-1.1.10                          
CMAKE_USE_PTHREADS             *ON   
FLTK_USE_SYSTEM_JPEG           *OFF                       
FLTK_USE_SYSTEM_PNG            *OFF                                                     
FLTK_USE_SYSTEM_ZLIB           *OFF
USE_OPENGL                  
   
   
*ON 
sudo make

エラー:
[ 53%] Building CXX object src/CMakeFiles/fltk.dir/filename_isdir.o
[ 54%] Building CXX object src/CMakeFiles/fltk.dir/filename_list.o
/usr/local/src/fltk-1.1.10/src/filename_list.cxx: In function ‘int fl_filename_list(const char*, dirent***, int (*)(dirent**, dirent**))’:
/usr/local/src/fltk-1.1.10/src/filename_list.cxx:70:68: error: invalid conversion from ‘int (*)(const void*, const void*)’ to ‘int (*)(const dirent**, const dirent**)’ [-fpermissive]
  int n = scandir(d, list, 0, (int(*)(const void*,const void*))sort);
                                                                  ^
In file included from/usr/local/src/fltk-1.1.10/FL/filename.H:91:0,
               from/usr/local/src/fltk-1.1.10/src/filename_list.cxx:30:
/usr/include/dirent.h:256:12: error:   initializing argument 4 of ‘int scandir(const char*, dirent***, int (*)(const dirent*), int (*)(const dirent**, const dirent**))’ [-fpermissive]
extern int scandir (__const char *__restrict __dir,
          ^
make[2]: *** [src/CMakeFiles/fltk.dir/filename_list.o] Error 1
make[1]: *** [src/CMakeFiles/fltk.dir/all] Error 2
make: *** [all] Error 2
解決方法:
開く
/usr/local/src/fltk-1.1.10/src/filename_list.cxxファイル、70行目の
int n = scandir(d, list, 0, (int(*)(const void*,const void*))sort);
置換
int n = scandir(d, list, 0, (int(*)(const dirent**, const dirent**))sort);
保存、終了.
sudo make

コンパイルパス
sudo make install
のインストールに成功しました.
参照先:
http://forums.gentoo.org/viewtopic-p-5855804.html?sid=727c9b485690e762a5c29204c80c363a
https://www.mail-archive.com/[email protected]/msg13896.html
ここではこの誤った原理を非常によく説明します.
The newer compilers don't like it if you try to assign a 64bit pointer/directly/into an int; it stops the build with a fatal "loss of precision"error.. g++ has no way to disable such errors AFAIK. We did this a lot because we use 'user_data' (which is a void*) to temporarily store all kinds of stuff, including ints. Our use is OK, because if we put a 32bit value into a 64bit pointer, then take it back out as a 32bit value, there's no loss.. but the compiler doesn't know that, and throws an error that can't be disabled.
The first part of the error says: invalid conversion from ‘int (*)(const void*, const void*)’ ..so that's what FLTK is passing the scandir function: a function pointer that returns an int and takes two arguments that are 'const void*'s.
The error goes on to say:
to ‘int (*)(const dirent**, const dirent**)’ ..which tells us what the scandir function is actually/expecting/a function pointer that returns an int and takes two arguments that are const dirent**'s. Function pointers are syntactically messy, but basically what has to happen here is you need to recast the func pointer from the former to the latter. The FLTK line in question currently reads: return scandir(d, list, 0, (int(*)(const void*,const void*))numericsort);                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The underlined bit is the problem, and is itself trying to re-cast the function pointer 'numericsort' from whatever it is to be a function that takes two const void*'s, but what the compiler/wants/to see is two const dirent **'s. So I think if you just change the two instances of "const void*" in that line to const dirent**'s, that should fix it, I'd think.
私はそうしました.確かにokです.
インストールに成功しました.