docopt.cpp
docopt.cpp copied to clipboard
Docopt is not working on a Qt project
Hi,
I tried to create a Qt project (Qt 5.8 + QtCreator 4.2.1) with just docopt and the main class, and it seems that for some reason Qmake does not understand the docopt.cpp as a source file. Therefore, it does not create an object and fails to link. If I enable the inline mode, it works, but I can't use this way in my original code since I am using docopt in several modules. I looked into the Makefile and indeed and it does not create the rule for docopt.cpp. Someone has a clue why this is happening?
The project file example:
TEMPLATE = app
CONFIG += console c++14
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += main.cpp \
docopt.cpp
HEADERS += \
docopt.h \
docopt_private.h \
docopt_util.h \
docopt_value.h
The compilation log:
g++ -c -pipe -g -std=gnu++1y -Wall -W -fPIC -DQT_QML_DEBUG -I../docopt2 -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o main.o ../docopt2/main.cpp
g++ -o test main.o
main.o: In functionmain': /home/programming/docopt2/main.cpp:18: undefined reference todocopt::docopt(std::string const&, std::vector<std::string, std::allocatorstd::string > const&, bool, std::string const&, bool)' collect2: error: ld returned 1 exit status
Ok, I found a workaround to force the docopt object generation. It is necessary to add the following code in the project:
SOURCES_FORCE = docopt.cpp
docopt_forced.name = docopt_forced
docopt_forced.input = SOURCES_FORCE
docopt_forced.dependency_type = TYPE_C
docopt_forced.variable_out = OBJECTS
docopt_forced.output = ${QMAKE_VAR_OBJECTS_DIR}${QMAKE_FILE_IN_BASE}$${first(QMAKE_EXT_OBJ)}
docopt_forced.commands = $${QMAKE_CXX} $(CXXFLAGS) $(INCPATH) -c ${QMAKE_FILE_IN} -o ${QMAKE_FILE_OUT}
QMAKE_EXTRA_COMPILERS += docopt_forced
Is there anything more we can help you with on this? Sorry for late reply. Just trying to go through issues to see which still need addressed.
Hi Jared,
I left that project a long time ago. The workaround was fine but I don't know if the problem still exists.