rockowitz / ddcui

Graphical user interface for ddcutil - control monitor settings
http://www.ddcutil.com
GNU General Public License v2.0
147 stars 2 forks source link

CMakeFiles/ddcui.dir/src/main/monitor.cpp.o: In function `Monitor::Monitor(DDCA_Display_Info*, int)' #28

Open gadefox opened 2 years ago

gadefox commented 2 years ago

I'm getting an error msg (see bellow). Any idea? Configuration: Ubuntu 18.04, ddutils 1.1.0 (successfully built), Qt5.15.2 (qt515webengine, qt515tools submodules w/ dependencies into /opt/qt515)

CMakeFiles/ddcui.dir/src/main/monitor.cpp.o: In function Monitor::Monitor(DDCA_Display_Info*, int)': monitor.cpp:(.text+0x29): undefined reference tovtable for Monitor' monitor.cpp:(.text+0x96): undefined reference to Monitor::metaObject() const' CMakeFiles/ddcui.dir/src/main/monitor.cpp.o: In functionMonitor::~Monitor()': monitor.cpp:(.text+0x14c): undefined reference to `vtable for Monitor' collect2: error: ld returned 1 exit status make[2]: [CMakeFiles/ddcui.dir/build.make:912: ddcui] Error 1 make[1]: [CMakeFiles/Makefile2:124: CMakeFiles/ddcui.dir/all] Error 2 make: *** [Makefile:149: all] Error 2

rockowitz commented 2 years ago

First, I assume you're building from branch 0.2.0-dev, which will soon be released. The master branch is ancient.

If class Monitor lacks a vtable something has gotten out of sync in the build.

My script for running cmake contains the following lines to ensure that stale values and cached files are not used:

rm CMakeCache.txt
# if sudo make uninstall has been run, files CMakeFiles/uninsall.dir/ depend.internal and depend.make will be owned by root, only root can erase:
sudo rm -r CMakeFiles
gadefox commented 2 years ago

In this case please upload the ddcutil dev branch too, because now I'm getting an error that the function ‘ddca_add_trace_groups’ was not declared in this scope. Thanks.

rockowitz commented 2 years ago

Use ddcutil branch 1.1.1-dev, which is the current development branch.

gadefox commented 2 years ago

No difference.. Could be this problem caused by an Q_OBJECT(?) - I can't find the implementation of all these functions.

rockowitz commented 2 years ago

On a hunch that there are 2 definitions of class Monitor at compilation time, I have replaced all forward declarations "class Monitor" in header files with "include base/monitor.h", and uploaded the changes to branch 0.2.0-dev. Whether or not the changes solve the problem, please submit the make output. Thanks.

gadefox commented 2 years ago

Your change doesn't solve the problem, but I moved the "monitor" header file, updated all #includes and everything is fine now. Why don't you use qmake instead of cmake? This problem is poorly documented, most users don't have it because the header files are automatically processed by moc if they are in the same folder as the associated cpp. The following link could help you. The header files have to be added to the project using an add_executable or add_library statement. If this is not done, automoc won't parse the files.

rockowitz commented 2 years ago

You are quite right about the vtable problem being the result of monitor.h not being processed by the MOC. I owe you an apology for your effort. I forgot that the problem had been addressed over 2 years ago, albeit with a hack, by adding a symbolic link from src/main/monitor.h to src/base/monitor.h. See file src/main/NOTES.TXT. Did the symbolic link get lost when you downloaded the source? If so, how did you download it? As you point out, using set_executable is a more proper way to address the problem.

Why is monitor.h located in src/base, not src/main with monitor.cpp? For clarity. I try to make the dependencies of source directories form a directed graph.

Why cmake and not qmake? Initially both were implemented. I chose to focus on cmake because it is more generally used. If someone wants to bring ddcui.pro up to production level quality I am amenable to distributing it as well. (ddcui.pro currently exists only in my source tree, not on github.)

Regards, Sanford

gadefox commented 2 years ago

Yes, I can see your NOTES, although it doesn't solve the problem - I'm getting the same linking error.. I need to build the latest Qt5 before further testing and I'll let you know..

ren@local:~/.build/gcc-11.2.0/build$ ls -la ~/.build/ddcui-0.2.0-dev/src/main/monitor.h -rwxrwxrwx 1 ren ren 17 júl 21 06:10 /home/ren/.build/ddcui-0.2.0-dev/src/main/monitor.h

ren@local: ~/.build/gcc-11.2.0/build$ ln -sf ~/.build/ddcui-0.2.0-dev/src/base/monitor.h /home/ren/.build/ddcui-0.2.0-dev/src/main/monitor.h

ren@local:~/.build/gcc-11.2.0/build$ ls -la ~/.build/ddcui-0.2.0-dev/src/main/monitor.h lrwxrwxrwx 1 ren ren 51 júl 30 21:42 /home/ren/.build/ddcui-0.2.0-dev/src/main/monitor.h -> /home/ren/.build/ddcui-0.2.0-dev/src/base/monitor.h

I downloaded the code using git..

rockowitz commented 2 years ago

The latest updates to branch 0.2.0-dev add src/base/monitor.h to the source file list for set_executable(), and eliminate the symbolic link hack from src/main/monitor.h to src/base/monitor.h.

Please rerun cmake (and of course make) and let me know if ddcui builds cleanly. If not, submit the output of cmake and make VERBOSE=1 as attachments, which will hopefully give a clue as to how your environment differs from mine.

Thank you.