(Newbie) CMake + prebuilt libraries linkage

Hello,

I’ve been trying to build a simple demo project using CMake, Qt Creator and MSVC compiler.

I generated prebuilt libraries and proceeded to linking my project.
I started with just “libcocos2d_2013.lib”, but the linker complained, so I added the following ones as well:

target_link_libraries(${APP_NAME}
        ${CMAKE_SOURCE_DIR}/Libs/libcocos2d_2013.lib
	${CMAKE_SOURCE_DIR}/Libs/libpng.lib
	${CMAKE_SOURCE_DIR}/Libs/libjpeg.lib
	${CMAKE_SOURCE_DIR}/Libs/libtiff.lib
	${CMAKE_SOURCE_DIR}/Libs/glfw3.lib
	${CMAKE_SOURCE_DIR}/Libs/libchipmunk.lib
	${CMAKE_SOURCE_DIR}/Libs/libbox2d_2013.lib
	${CMAKE_SOURCE_DIR}/Libs/libSpine_2013.lib
	${CMAKE_SOURCE_DIR}/Libs/librecast_2013.lib
	${CMAKE_SOURCE_DIR}/Libs/libbullet_2013.lib
)

I’m getting a huge pile of LNK2019 and LNK2001 “unresolved external symbol” errors. Like this:

AppDelegate.cpp.obj:-1: error: LNK2019: unresolved external symbol "public: __cdecl cocos2d::Rect::Rect(float,float,float,float)" (??0Rect@cocos2d@@QEAA@MMMM@Z) referenced in function "public: virtual bool __cdecl AppDelegate::applicationDidFinishLaunching(void)" (?applicationDidFinishLaunching@AppDelegate@@UEAA_NXZ)

I’ve also tried building that demo for Android using command line with following lines preceding my actual project in Android.mk:

LOCAL_MODULE := cocos2d_static
LOCAL_SRC_FILES := ../../Libs/libcocos2d.a
LOCAL_C_INCLUDES := ../../headers/cocos
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)

I get pretty much the same pile of linker errors.

I got a feeling like I’m missing something most people consider obvious here. Can anyone explain?

Where did you get this naming convention? I don’t recognize it. Are you using Cocos2d-x? What version? Where did you get it from?

I’ve pre-built the libraries with “cocos gen-libs -p win32”. The compiler is from Visual Studio 2013, but I don’t want to rely on the IDE, because I don’t want any “magic” I don’t understand to happen behind the scenes.

I’ve also tried this on Linux (GCC) with similarly generated “.a” files. I’m getting the same result.

Cocos version I’m using is 3.13.1

As for CMakeLists.txt, I wrote it myself, the “-t binary” generated project doesn’t include one.

As for the other libs (chipmunk, recast etc.) I don’t use them in my project directly. Cocos2d uses them and the linker complains when they aren’t linked. To my untrained eye it looks as if the prebuilt libcocos2d files (both “.lib” and “.a”) were not self-contained and required some sort of additional processing before they can be used.

Interesting. I didn’t realize there was a 2013 appended to the end of the library name. I assume this is the same for 2015. I have some VS 2017 testing on my list for later this week. I will have a look at the cocos gen-libs step and see.