GillesDebunne / libQGLViewer

libQGLViewer is an open source C++ library based on Qt that eases the creation of OpenGL 3D viewers.
Other
241 stars 94 forks source link

build error: nullptr’ was not declared #51

Closed narutojxl closed 3 years ago

narutojxl commented 3 years ago

Hi all, My OS is ubuntu16.04, QMake version 3.0, Qt version 5.5.1 in /usr/lib/x86_64-linux-gnu, build libQGLViewer-2.7.2 from source, add c++11 to libQGLViewer-2.7.2.pro file as following according to qmake config, but it seems that it not work. Thanks for your help in advance a lot !

libQGLViewer-2.7.2.pro

CONFIG += ordered c++11 TEMPLATE = subdirs SUBDIRS = QGLViewer examples designerPlugin

QMAKE_CXXFLAGS += -std=c++11

QT_VERSION=$$[QT_VERSION]

equals (QT_MAJOR_VERSION, 5) {
    cache()
}

build command

$cd libQGLViewer-2.7.2/ $mkdir build $cd libQGLViewer-2.7.2/build $qmake .. $make

some error output is:

In file included from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/camera.h:27:0, from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.h:26, from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.cpp:23: /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/keyFrameInterpolator.h:137:3: warning: identifier ‘nullptr’ is a keyword in C++11 [-Wc++0x-compat] KeyFrameInterpolator(Frame fr = nullptr); ^ /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/keyFrameInterpolator.h:137:36: error: ‘nullptr’ was not declared in this scope KeyFrameInterpolator(Frame fr = nullptr); ^ In file included from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.h:26:0, from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.cpp:23: /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/camera.h:432:67: error: ‘nullptr’ was not declared in this scope Vec projectedCoordinatesOf(const Vec &src, const Frame *frame = nullptr) const;

GillesDebunne commented 3 years ago

As stated in the comment, nullptr is a keyword introduced in C++11. Either upgrade your compiler version, or search and replace nullptr by 0 (zero), it should solve the problem.

On Tue, Dec 15, 2020 at 9:35 AM narutojxl notifications@github.com wrote:

Hi all, My OS is ubuntu16.04, QMake version 3.0, Qt version 5.5.1 in /usr/lib/x86_64-linux-gnu, build libQGLViewer-2.7.2 http://libqglviewer.com/installUnix.html#linux from source, add c++11 to libQGLViewer-2.7.2.pro file as following according to qmake config https://doc.qt.io/qt-5/qmake-variable-reference.html#config, but it seems that it not work. Thanks for your help in advance a lot !

CONFIG += ordered c++11

TEMPLATE = subdirs

SUBDIRS = QGLViewer examples designerPlugin

QT_VERSION=$$[QT_VERSION]

equals (QT_MAJOR_VERSION, 5) {

cache()

}

some error output is:

In file included from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/camera.h:27:0,

       from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.h:26,

       from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.cpp:23:

/home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/keyFrameInterpolator.h:137:3: warning: identifier ‘nullptr’ is a keyword in C++11 [-Wc++0x-compat]

KeyFrameInterpolator(Frame *fr = nullptr);

^

/home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/keyFrameInterpolator.h:137:36: error: ‘nullptr’ was not declared in this scope

KeyFrameInterpolator(Frame *fr = nullptr);

                          ^

In file included from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.h:26:0,

       from /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/qglviewer.cpp:23:

/home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/camera.h:432:67: error: ‘nullptr’ was not declared in this scope

Vec projectedCoordinatesOf(const Vec &src, const Frame *frame = nullptr) const;

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/GillesDebunne/libQGLViewer/issues/51, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOPFGUF2MNTYYJFGGOXG23SU4NV7ANCNFSM4U3655RA .

narutojxl commented 3 years ago

Hi @GillesDebunne. Thanks for your kind reply. My gcc and g++ version are 5.4.0, i found nullptr is supported from the version gcc 4.6, as in here, so my gcc should support C++11, i guess. I'm confused about qmake config to enable C++11, any suggestions?
image

GillesDebunne commented 3 years ago

This might help: https://stackoverflow.com/questions/16509932/using-qt-creator-c-11-nullptr-is-keyworded

On Tue, Dec 15, 2020 at 12:46 PM narutojxl notifications@github.com wrote:

Hi @GillesDebunne https://github.com/GillesDebunne. Thanks for your kind reply. My gcc and g++ version are 5.4.0, i found nullptr is supported from the version gcc 4.6, as in here https://gcc.gnu.org/projects/cxx-status.html, so my gcc should support C++11, i guess. I'm confused about qmake config to enable C++11, any suggestions? [image: image] https://user-images.githubusercontent.com/6205343/102210808-a0cf5880-3f0d-11eb-8520-5772f69b48a5.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GillesDebunne/libQGLViewer/issues/51#issuecomment-745237541, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOPFGX5QIWPLX3BTXJKZW3SU5EA5ANCNFSM4U3655RA .

narutojxl commented 3 years ago

CONFIG += ordered c++11 and QMAKE_CXXFLAGS += -std=c++11 all not work, it's werid. I'm ready to replace nullptr with 0 to build. It's not libQGLViewer's problem, so if anyone find out the solution when building, please give a comment, thanks for your time and help. Close it now.

lrineau commented 3 years ago

As stated in the comment, nullptr is a keyword introduced in C++11. Either upgrade your compiler version, or search and replace nullptr by 0 (zero), it should solve the problem.

The first compiler diagnostic is

warning: identifier ‘nullptr’ is a keyword in C++11 [-Wc++0x-compat]

That says that the compiler knows the nullptr keyword, but the C++11 mode is not used. The issue is the build system (the qmake configuration). @narutojxl, in the build log, do you see a warning about -std=c++11 being unknown and ignored by the compiler? Maybe that version only knows the compilation option -std=c++0x.

narutojxl commented 3 years ago

Hi @lrineau, thanks for your reply.
I don't find a build log, grep -nr "c++11" ./ in the build directory, there is no output. Use with QMAKE_CXXFLAGS += -std=c++0x not work, so I download a new version Qt5.12.4 following your advice and installed in /home/jxl/Qt5.12.4. Config as following:

jxl@dell:/usr/lib/x86_64-linux-gnu/qt-default/qtchooser$ ls default.conf jxl@dell:/usr/lib/x86_64-linux-gnu/qt-default/qtchooser$ sudo gedit default.conf /home/jxl/Qt5.12.4/5.12.4/gcc_64/bin /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib

#deleta old link, create a new one to link our installed version
jxl@dell:~$sudo rm /usr/bin/qmake
jxl@dell:/usr/bin$ sudo ln -s /home/jxl/Qt5.12.4/5.12.4/gcc_64/bin/qmake   /usr/bin/qmake 
jxl@dell:/usr/bin$ qmake -v
QMake version 3.1
Using Qt version 5.12.4 in /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib
jxl@dell:/usr/bin$

Delete old build directory and create a new clean one to rebuild, the output tells me: /usr/bin/ld: can not find -lQGLViewer-qt5. It seems that about issues/32. Look forward to disscuss with you : D

terminal output about libQGLViewer-qt5.so:

jxl@dell:~/third_softwares/libQGLViewer-2.7.2/build$ make ln -s libQGLViewer-qt5.so.2.7.2 libQGLViewer-qt5.so ln -s libQGLViewer-qt5.so.2.7.2 libQGLViewer-qt5.so.2 ln -s libQGLViewer-qt5.so.2.7.2 libQGLViewer-qt5.so.2.7 rm -f /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so.2.7.2 mv -f libQGLViewer-qt5.so.2.7.2 /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so.2.7.2 rm -f /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so rm -f /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so.2 rm -f /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so.2.7 mv -f libQGLViewer-qt5.so /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so mv -f libQGLViewer-qt5.so.2 /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so.2 mv -f libQGLViewer-qt5.so.2.7 /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so.2.7

cd QGLViewer/ && ( test -e Makefile || /usr/bin/qmake -o Makefile /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/QGLViewer.pro ) && make -f Makefile 
make[1]: Entering directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/QGLViewer'
make[1]: Nothing to be done for 'first'.
make[1]: Leaving directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/QGLViewer'
cd examples/ && ( test -e Makefile || /usr/bin/qmake -o Makefile /home/jxl/third_softwares/libQGLViewer-2.7.2/examples/examples.pro ) && make -f Makefile 
make[1]: Entering directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/examples'
cd animation/ && ( test -e Makefile || /usr/bin/qmake -o Makefile /home/jxl/third_softwares/libQGLViewer-2.7.2/examples/animation/animation.pro ) && make -f Makefile 
make[2]: Entering directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/examples/animation'
g++ -Wl,-O1 -Wl,-rpath,/home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer -Wl,-rpath,/home/jxl/Qt5.12.4/5.12.4/gcc_64/lib -o animation .obj/animation.o .obj/main.o   -L../../QGLViewer -lQGLViewer-qt5 -lpthread -lGL /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5OpenGL.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Widgets.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Gui.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Xml.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Core.so   
/usr/bin/ld: 找不到 -lQGLViewer-qt5
collect2: error: ld returned 1 exit status
Makefile:72: recipe for target 'animation' failed
make[2]: *** [animation] Error 1
make[2]: Leaving directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/examples/animation'
Makefile:69: recipe for target 'sub-animation-make_first' failed
make[1]: *** [sub-animation-make_first] Error 2
make[1]: Leaving directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/examples'
Makefile:91: recipe for target 'sub-examples-make_first-ordered' failed
make: *** [sub-examples-make_first-ordered] Error 2
jxl@dell:~/third_softwares/libQGLViewer-2.7.2/build$ 
jxl@dell:~/third_softwares/libQGLViewer-2.7.2/build$ 

I try some solutions all not work.

libQGLViewer-2.7.2/QGLViewer exists libQGLViewer-qt5.so.

jxl@dell:~/third_softwares/libQGLViewer-2.7.2/QGLViewer$ ll libQGLViewer-qt5 -rw-rw-r-- 1 jxl jxl 481 12月 16 11:27 libQGLViewer-qt5.prl lrwxrwxrwx 1 jxl jxl 25 12月 16 11:28 libQGLViewer-qt5.so -> libQGLViewer-qt5.so.2.7.2 lrwxrwxrwx 1 jxl jxl 25 12月 16 11:28 libQGLViewer-qt5.so.2 -> libQGLViewer-qt5.so.2.7.2 lrwxrwxrwx 1 jxl jxl 25 12月 16 11:28 libQGLViewer-qt5.so.2.7 -> libQGLViewer-qt5.so.2.7.2 -rwxrwxr-x 1 jxl jxl 797416 12月 16 11:28 libQGLViewer-qt5.so.2.7.2* jxl@dell:~/third_softwares/libQGLViewer-2.7.2/QGLViewer$

lrineau commented 3 years ago

make[2]: Entering directory '/home/jxl/third_softwares/libQGLViewer-2.7.2/build/examples/animation' g++ -Wl,-O1 -Wl,-rpath,/home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer -Wl,-rpath,/home/jxl/Qt5.12.4/5.12.4/gcc_64/lib -o animation .obj/animation.o .obj/main.o -L../../QGLViewer -lQGLViewer-qt5 -lpthread -lGL /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5OpenGL.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Widgets.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Gui.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Xml.so /home/jxl/Qt5.12.4/5.12.4/gcc_64/lib/libQt5Core.so

That is strange. Here the compilation process is in /home/jxl/third_softwares/libQGLViewer-2.7.2/build/examples/animation, and parts of the linker flags are: -L../../QGLViewer -lQGLViewer-qt5. That means those flags expect libQGLViewer-qt5.so to be in /home/jxl/third_softwares/libQGLViewer-2.7.2/build/QGLViewer, but it is actually in /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer, as we can see in another part of the log:

mv -f libQGLViewer-qt5.so /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so

@GillesDebunne It seems that means a bug in the build system of QGLViewer.

gdebunne commented 3 years ago

It seems correct to me : a path of ../../QGLViewer applied in libQGLViewer-2.7.2/build/examples/animation refers to libQGLViewer-2.7.2/build/QGLViewer as expected. Isn't it ?

lrineau commented 3 years ago

It seems correct to me : a path of ../../QGLViewer applied in libQGLViewer-2.7.2/build/examples/animation refers to libQGLViewer-2.7.2/build/QGLViewer as expected. Isn't it ?

It is expected that it is in libQGLViewer-2.7.2/build/QGLViewer, but it is actually in libQGLViewer-2.7.2/QGLViewer:

mv -f libQGLViewer-qt5.so /home/jxl/third_softwares/libQGLViewer-2.7.2/QGLViewer/libQGLViewer-qt5.so

gdebunne commented 3 years ago

This build directory is not part of the standard libQGLViewer directory structure. I guess it was created by the original poster, and that may explain the problems. My advice is to start from a clean install, only fixing the compiler flag in the .pro to support nullptr.

lrineau commented 3 years ago

The original poster wrote his build commands:

build command

$ cd libQGLViewer-2.7.2/
$ mkdir build
$ cd libQGLViewer-2.7.2/build
$ qmake ..
$ make 

qmake supports out-of-sources builds, but it seems there is a bug when an out-of-sources build is used on QGLViewer.

GillesDebunne commented 3 years ago

The ../../QGLViewer relative path is only used when building the examples, not the core library. It is a way to automatically use (if found) the library and its include files, without having to install it, which usually requires root privileges. Using qmake [INCLUDE_DIR=...] [LIB_DIR=...] is also an option to specify local paths to the include files and the lib. That being said, out-of-sources builds could probably be better supported.

On Wed, Dec 16, 2020 at 7:34 PM Laurent Rineau notifications@github.com wrote:

The original poster wrote his build commands:

build command

$ cd libQGLViewer-2.7.2/ $ mkdir build $ cd libQGLViewer-2.7.2/build $ qmake .. $ make

qmake supports out-of-sources builds, but it seems there is a bug when an out-of-sources build is used on QGLViewer.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GillesDebunne/libQGLViewer/issues/51#issuecomment-746790870, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOPFGRNQSVA2EI67DPMOMLSVD4SPANCNFSM4U3655RA .

narutojxl commented 3 years ago

Hi @GillesDebunne and @lrineau, thank you for help me to solve this problem very much! in source build with either of the following config of libQGLViewer-2.7.2.pro file all work :+1:

CONFIG += ordered c++11
QMAKE_CXXFLAGS += -std=c++11