cmake generates library file with error undefined function

duyu193 注册会员
2023-02-28 01:41

I checked and it seems that it is not the three cases you said


This is the content of doipcommon layer CMakelists. The configuration information is the same as that of doipserver. include files are configured in the top layer CMakelists.

ds1989126 注册会员
2023-02-28 01:41

The following reasons may cause an error with undefined functions when generating library files:

  1. compiled without adding the folder where message.h resides to the include path, causing the compiler to miss the header file. In the top-level CMakeLists.txt, the include path for doipcommon has been added:
target_include_directories(doipcommon PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)

但是对于 doipserver,没有添加 include 路径,需要将其添加:


target_include_directories(doipserver PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
  1. In doipserver.cpp, there may be a discrepancy between function declaration and function definition. Check that doipserver.cpp has a definition for the DOIPServer::receive() function and that its arguments and return values are the same as those declared in message.h. If the definition and declaration do not agree, the error of undefined function occurs.
  1. There may be multiple message.h files, and the compiler loads a message.h file that does not contain the target function declaration. Check whether multiple message.h files exist in the system, and ensure that the compiler loads the message.h file in the path where the target file resides.

About the Author

Question Info

Publish Time
2023-02-28 01:41
Update Time
2023-02-28 01:41