cppcms icon indicating copy to clipboard operation
cppcms copied to clipboard

symbol lookup error: libview.so: undefined symbol

Open masaoliou opened this issue 2 years ago • 1 comments

Hi!

After I made some modifications on .cpp and .h files, the new version of executable my_website began to crash and print the following message:

/usr/local/bin/my_website/my_website: symbol lookup error: /usr/local/lib/my_website/libview.so: undefined symbol: _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

c++filt eats _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE and prints the following line:

main_thread::site_value(unsigned int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)

my_website.tmpl contains the following code:

<% c++ out() << content.p_main_thread->site_value(content.language,"banner"); %>

Executalbe my_website-old is the old version that runs normally. nm my_website-old | grep site_value prints the following messages:

000000000008f820 T _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
000000000005108e t _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE.cold
000000000008d6b0 T _ZN11main_thread17global_site_valueERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

There is no private: std::string site_value(unsigned int language,const std::string &name); defined in my_website.h. I have no idea why the above line with t appears.

nm -D my_website-old | grep site_value prints the following messages:

000000000008f820 T _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
000000000008d6b0 T _ZN11main_thread17global_site_valueERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

nm my_website | grep site_value prints the following messages:

000000000003efb4 T _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE
000000000003ef22 T _ZN11main_thread17global_site_valueERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

nm -D my_website | grep site_value prints nothing.

libview-old.so is the old version that runs normally. Both nm libview-old.so | grep site_value and nm libview.so | grep site_value print the following identical line:

                 U _ZN11main_thread10site_valueEjRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE

File CMakeLists.txt has been intact:

add_executable(my_website ${SRC})
add_library(view SHARED ${CMAKE_CURRENT_BINARY_DIR}/view.cpp)
target_link_libraries(view ${BOOSTER} ${CPPCMS})

The following public method for executable my_website has been intact, too.

//.h
public:
	std::string site_value(unsigned int language,const std::string &name);

//.cpp
std::string main_thread::site_value(unsigned int language,const std::string &name)
{
  ...
}

CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)
project(my_website)

include(CPack)

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Debug CACHE STRING
        "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
	      FORCE)
endif(NOT CMAKE_BUILD_TYPE)

option(USE_STATIC_VIEW "Compile view statically" OFF)

if(CMAKE_COMPILER_IS_GNUCXX)
    set(CMAKE_CXX_FLAGS "-std=c++17")	## std::map::try_emplace
endif()

find_library(CPPCMS cppcms)
find_library(BOOSTER booster)
find_library(CPPDB cppdb)
find_library(MARKDOWN markdown)

find_path(CPPCMS_INC cppcms/application.h)
find_path(BOOSTER_INC booster/shared_ptr.h)
find_path(CPPDB_INC cppdb/frontend.h)
find_path(MARKDOWN_INC mkdio.h)

set(Boost_USE_STATIC_LIBS		OFF)
set(Boost_USE_MULTITHREADED		ON)
set(Boost_USE_STATIC_RUNTIME	OFF)
find_package(Boost COMPONENTS system date_time filesystem thread)
if(Boost_FOUND)
	include_directories(${Boost_INCLUDE_DIRS})
else()
	message(FATAL 	"-- BOOST libraries are required but not found\n")
endif()

if(NOT MARKDOWN_INC OR NOT MARKDOWN)
	message(FATAL	"-- Discount markdown library is not found, please install Debian package libmarkdown2-dev")
endif()

include_directories(${CPPCMS_INC})
include_directories(${BOOSTER_INC})
include_directories(${MARKDOWN_INC})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/cpp)
include_directories(${Boost_INCLUDE_DIR})

if(CPPCMS_INC)
	include_directories("../cppcms_private")
endif()

find_program(TMPLCC cppcms_tmpl_cc)
find_program(XGETTEXT xgettext)
find_program(MSGFMT msgfmt)
if(NOT MSGFMT)
	message(FATAL "-- msgfmt is not found, please install Debian package gettext")
endif()
find_program(MSGMERGE msgmerge)

set(TEMPLATES
	${CMAKE_CURRENT_SOURCE_DIR}/template/master.tmpl
	${CMAKE_CURRENT_SOURCE_DIR}/template/edit_site.tmpl
	${CMAKE_CURRENT_SOURCE_DIR}/template/home.tmpl
	${CMAKE_CURRENT_SOURCE_DIR}/template/article.tmpl
	${CMAKE_CURRENT_SOURCE_DIR}/template/user.tmpl
)

set(SRC 
	cpp/utils.cpp
	cpp/main.cpp
	cpp/main_thread.cpp
	cpp/multi_thread.cpp
	cpp/home.cpp
	cpp/edit_site.cpp
	cpp/user.cpp
	cpp/article.cpp
)

add_custom_command(
	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/view.cpp
	COMMAND ${TMPLCC}
		-d my_website
		-o ${CMAKE_CURRENT_BINARY_DIR}/view.cpp 
		${TEMPLATES}
	DEPENDS ${TEMPLATES})


if(USE_STATIC_VIEW)
	add_executable(my_website ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/view.cpp)
else()
	add_executable(my_website ${SRC})
	add_library(view SHARED ${CMAKE_CURRENT_BINARY_DIR}/view.cpp)
	target_link_libraries(view ${BOOSTER} ${CPPCMS})
endif()


target_link_libraries(my_website ${BOOSTER} ${CPPCMS} ${CPPDB} ${CURL} ${MARKDOWN} ${Boost_LIBRARIES} ${PQ_LIB} ${OPENSSL_CRYPTO_LIB})

set(LOCALES zh_TW zh_CN)
set(MO_FILES)
set(UPDATE_PO_LIST)
set(POT_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/po/my_website.pot")
add_custom_command(
	OUTPUT ${POT_TEMPLATE}
	COMMAND 
		${XGETTEXT} 
		--keyword=translate:1,1t
		--keyword=translate:1,2,3t
		--keyword=_
		--keyword=N_
		${SRC}
		${CMAKE_CURRENT_BINARY_DIR}/view.cpp
		--output=${POT_TEMPLATE}
	DEPENDS ${SRC} ${CMAKE_CURRENT_BINARY_DIR}/view.cpp
	WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
	)
add_custom_target(update-po)

foreach(LOCALE ${LOCALES})
	set(MODIR "${CMAKE_CURRENT_BINARY_DIR}/locale/${LOCALE}/LC_MESSAGES")
	file(MAKE_DIRECTORY "${MODIR}")
	set(MOFILE "${MODIR}/my_website.mo")
	set(POFILE "${CMAKE_CURRENT_SOURCE_DIR}/po/${LOCALE}.po")
	
	add_custom_command(
		OUTPUT ${MOFILE}
		COMMAND ${MSGFMT} ${POFILE} -o ${MOFILE}
		DEPENDS ${POFILE})
	
	add_custom_target(update-po-${LOCALE}
		COMMAND ${MSGMERGE} -U ${POFILE} ${CMAKE_CURRENT_SOURCE_DIR}/po/my_website.pot 
		DEPENDS ${POT_TEMPLATE}
		)
	add_dependencies(update-po update-po-${LOCALE})

	set(MO_FILES ${MO_FILES} ${MOFILE})
	set(UPDATE_PO_LIST ${UPDATE_PO_LIST} update-po-${LOCALE})
endforeach()

add_custom_target(create-po ALL DEPENDS ${MO_FILES})


if(USE_STATIC_VIEW)
	install(TARGETS my_website
		RUNTIME DESTINATION bin/my_website)
else()
	install(TARGETS my_website view
		RUNTIME DESTINATION bin/my_website
		LIBRARY DESTINATION lib/my_website
		ARCHIVE DESTINATION lib/my_website)
endif()

foreach(LOCALE ${LOCALES})
	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/locale/${LOCALE}/LC_MESSAGES/my_website.mo 
		DESTINATION share/locale/${LOCALE}/LC_MESSAGES/)
endforeach()

option(USE_STATIC_VIEW "Compile view statically" ON) doesn't prevent my_website from crash.

Any pointer will be greatly appreciated!

masaoliou avatar Sep 19 '23 12:09 masaoliou

The problem lies in the most unexpected place - file CMakeList.txt.

The program doesn't crash if I replace the first line cmake_minimum_required(VERSION 3.18) with cmake_minimum_required(VERSION 2.6), which produces the following annoying warnings:

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

My another application that does not use template runs normally with cmake_minimum_required(VERSION 3.18).

Any idea?

---Edit--- I changed 2.0.0.beta2 source files cppcms/CMakeLists.txt and cppcms/booster/CMakeLists.txt by replacing their cmake_minimum_required(VERSION 2.6) with cmake_minimum_required(VERSION 3.18). Then rebuilt and installed cppcms.

Then I rebuilt my application, configured with `cmake_minimum_required(VERSION 3.18)'. My application still crashes.

masaoliou avatar Sep 20 '23 08:09 masaoliou