c - libnfc cmake header file compilation error -
am programming nfc using libnfc library in c language. using tdm-gcc mingw compiler , cmake open source build system installed following this tutorial building/compiling code. trying compile program includes/imports header file having source file. part of header file (card_objects.h) is:
#ifndef card_objects_h_ #define card_objects_h_ ... //other code int setapplicationid(uint8_t *rapdu, char tag[], int currentpos); #endif
a part of source code file (card_objects.c) is:
#include "card_objects.h" ... //other code int setapplicationid(uint8_t *rapdu, char tag[], int currentpos) { ... //other code return currentpos; }
both files in include_dir/ directory @ current path relative main file. have called header file in main program file follows:
#include "include_dir/card_objects.h" ... //othercode int main(int argc, const char *argv[]) { .... //other code currentpos = setapplicationid(rapdu, "application id (aid): ", currentpos); ... //other code }
when try compile above program on computer, following error:
"... main_file.c:200: undefined reference 'setapplicationid'"
can figure out have done wrong? keep in mind have other header files no source files, variable definitions, being compiled no problem. header file-source file import , it's not working. see problem?
you cmakelists.txt file incorrect.
here original:
set(examples-sources main_file tests/test_progs ) include_directories(${cmake_current_source_dir}/../libnfc) include_directories(${cmake_current_source_dir}/include_dir) #this 2 files located # examples foreach(source ${examples-sources}) set (targets ${source}.c) if(win32) set(rc_comment "${package_name} example") set(rc_internal_name ${source}) set(rc_original_name ${source}.exe) set(rc_file_type vft_app) configure_file(${cmake_current_source_dir}/../contrib/win32/version.rc.in ${cmake_current_binary_dir}/../windows/${source}.rc @only) list(append targets ${cmake_current_binary_dir}/../windows/${source}.rc) endif(win32) add_executable(${source} ${targets}) target_link_libraries(${source} nfc) target_link_libraries(${source} nfcutils) install(targets ${source} runtime destination bin component examples) endforeach(source) #install required libraries if(win32) include(installrequiredsystemlibraries) configure_file(${cmake_source_dir}/cmake/fixbundle.cmake.in ${cmake_current_binary_dir}/fixbundle.cmake @only) install(script ${cmake_current_binary_dir}/fixbundle.cmake) endif(win32) if(not win32) # manuals examples file(glob manuals "${cmake_current_source_dir}/*.1") install(files ${manuals} destination ${share_install_prefix}/man/man1 component manuals) endif(not win32)
in foreach(source ${examples-sources})
section create 2 targets, each 1 has single c file, end set( targets main_file.c )
in first iteration , set( targets tests/test_progs.c)
on second iteration.
card_objects.c not referenced anywhere in cmakelists.txt file never built executable, hence undefined reference code isn't being built...
you should add cmake_minimum_required , project call cmakelists.txt file too.
perhaps example need use set( targets ${source}.c card_objects.c )
Comments
Post a Comment