0

I have some little project in C/C++, here is a CmakeList file

cmake_minimum_required(VERSION 2.8)

project (xmlcppwrapper)

file(GLOB SOURCE RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
file(GLOB HEADER RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h")

if(CMAKE_COMPILER_IS_GNUCXX)
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fmessage-length=0 -Wall -fPIC")
    set( CMAKE_CXX_FLAGS_DEBUG   "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3 -DDEBUG")
    set( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3" )
endif(CMAKE_COMPILER_IS_GNUCXX)

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
    /usr/local/include/libxml2/
    /usr/local/include/libxslt/
)

add_library(
    ${CMAKE_PROJECT_NAME}
    ${SOURCE}
)


target_link_libraries(
    ${CMAKE_PROJECT_NAME}
    xml2
)

add_executable(
    parser_h
    ${CMAKE_CURRENT_SOURCE_DIR}/example/main.cpp
)
target_link_libraries(
        parser_h
    ${CMAKE_PROJECT_NAME}
)

install(FILES ${HEADER} DESTINATION include) 
install(TARGETS ${CMAKE_PROJECT_NAME} DESTINATION lib) 

In the /usr/local/include/libxml2 and xslt folders have *.h files, and in /usr/local/lib folder libxml2.so and libxslt.so files

When I'd like to compile main.cpp

#include <iostream>
#include <fstream>
#include <cstring>
#include <xsltInternals.h>
#include <libxml2/libxml/xmlstring.h>
#include <attributes.h>

using namespace std;

int main(int argc, char* argv[]) {

    xsltStylesheetPtr style = (xsltStylesheetPtr) "";//xsltParseStylesheetFile((const xmlChar *) argv[1]);
    xmlNodePtr cur = (xmlNodePtr) "";

    xsltParseStylesheetAttributeSet(style,cur);

return 0;

}

I got always error undefined reference to `xsltParseStylesheetAttributeSet' How I can fix it? What I do wrong? Thank you

  • Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – too honest for this site Apr 16 '17 at 14:44
  • 1) Don't spam tags. There is no language C/C++ and this is clearly C++. 2) Do some research ony our own **before** contributiong the millionth duplicate question. – too honest for this site Apr 16 '17 at 14:45
  • I don't think, I use clion and he says that all libraries installed – admin adminov Apr 16 '17 at 14:46
  • The question (and answer) are not related to clion and thy exactly address your problem! If you don't understand them, does not mean they are relevant. Just because the unresolve symbol has a different name does not meant it is a different problem! – too honest for this site Apr 16 '17 at 14:55
  • @Olaf: His problem is different, he's already listing `libxslt` as a dependency in the makefile, he doesn't know how to get it passed on the linker command line. That's a "use of make system" question, which is 100% on-topic here. – Ben Voigt Apr 16 '17 at 23:52
  • @BenVoigt: I did not say it is off-topic. But I accept it might not a dup of the question I thought (we all can err), but it is most likely a dup of another one. - On a second thought, I thinkit actually **is** the correct dup; OP just needs to specify the library. This has nothing to do with dependencies (they are for building custom code, not linking system libraries) – too honest for this site Apr 17 '17 at 04:29
  • @olaf, I would not have written this question if had found an answer from other websites, `they are for building custom code, not linking system libraries` I linked library with -llibxslt command, but unfortunately – admin adminov Apr 17 '17 at 04:58
  • You probably have to add `xslt` to `target_link_libraries`. – nwellnhof Apr 20 '17 at 10:03

0 Answers0