Problem when define macro in Qt



  • I write some Qt code by using macro same source code of QtCreator. But, when I build it, I got problem:

    Here is my file code.

    @#ifndef QTC_ASSERT_H
    #define QTC_ASSERT_H

    #include "utils_global.h"

    namespace Utils { EDACREATOR_UTILS_EXPORT void writeAssertLocation(const char *msg); }

    #define QTC_ASSERT_STRINGIFY_HELPER(x) #x
    #define QTC_ASSERT_STRINGIFY(x) QTC_ASSERT_STRINGIFY_HELPER(x)
    #define QTC_ASSERT_STRING(cond) ::Utils::writeAssertLocation(
    """ cond"" in file " FILE ", line " QTC_ASSERT_STRINGIFY(LINE))

    #define QTC_ASSERT(cond, action) if (cond) {} else { QTC_ASSERT_STRING(#cond); action; } do {} while (0)
    #define QTC_CHECK(cond) if (cond) {} else { QTC_ASSERT_STRING(#cond); } do {} while (0)

    #endif // QTC_ASSERT_H

    #include "qtcassert.h"
    namespace Utils {

    void writeAssertLocation(const char *msg)
    {
    qDebug("SOFT ASSERT: %s", msg);
    }

    } // namespace Utils

    @

    After complie it, I got problem like this:
    @ undefined reference to `Utils::writeAssertLocation(char const*)'@

    How I can fix it? Thanks so much



  • Hi, in which file your code is put in?

    please move the definition of the function to a *.cpp file, and don't forgot to link it.



  • [quote author="1+1=2" date="1374455721"]Hi, in which file your code is put in?

    please move the definition of the function to a *.cpp file, and don't forgot to link it.[/quote]

    What is that mean? I don't understand what you say. Please give an example. Thank you.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.