Why “undefined reference” when the variable is defined and the library is linked?-Collection of common programming errors

Real problem in short: Circular library dependency between arch and synergy. Also, base actually wasn’t linked to common library (in the CMakeLists.txt for base).

Interestingly, this was caused by a configuration problem in the CMakeLists.txt files for the libraries. This had nothing to do with the CMakeLists.txt for the new synergyd application I had added.

The problem was that I did not link the libraries to each other where new calls were added to classes in other libraries. However, it seems that there is now a problem with circular linking.

For example, I could have added…

if (UNIX)
    target_link_libraries(arch synergy)
endif()

… to CMakeLists.txt in the arch library, as arch now calls something in the synergy library. But this is invalid, since synergy already calls something in arch.

Apparently this doesn’t matter on Windows.

I’m not quite sure though what caused this to start happening, as it’s all old code that has been compiling fine before, and still does in other applications. I suspect most likely something to do with the recent removal of boiler plate from CArch, rather than something that CDaemonApp is doing (or maybe even a combination of both).

Update

Just in case anyone cares 😉 — I think it is something to do with the relation between the lousy circular library dependency between arch and synergy, combined with the fact that CDaemonApp.cpp wasn’t including CApp.h — meaning that it was included at some other point, causing the weird undefined reference errors.

To solve this properly, I have removed the circular dependency, which appeared to be the core of the problem.

Update 2

The code now fully compiles, hurrah!

I was still seeing one last error (the topic of this question):

[ 90%] Building CXX object src/cmd/synergyd/CMakeFiles/synergyd.dir/synergyd.o
Linking CXX executable ../../../../../bin/debug/synergyd
../../../../../lib/debug/libbase.a(CLog.o): In function `CLog::insert(ILogOutputter*, bool)':
/home/nick/Projects/synergy/branches/1.4/src/lib/base/CLog.cpp:213: undefined reference to `kAppVersion'
collect2: ld returned 1 exit status
make[2]: *** [../../bin/debug/synergyd] Error 1
make[1]: *** [src/cmd/synergyd/CMakeFiles/synergyd.dir/all] Error 2
make: *** [all] Error 2

This was simply caused by the base library not linking to the common library. Adding the following code to the CMakeLists.txt file for base fixed this:

if (UNIX)
    target_link_libraries(base common)
endif()

Still not sure exactly why this started happening, just glad it’s fixed.

Update 3

And here’s the commit: r1354

Originally posted 2013-11-27 12:25:57.