karastojko / mailio

mailio is a cross platform C++ library for MIME format and SMTP, POP3, IMAP protocols. It is based on the standard C++ 17 and Boost library.
Other
381 stars 102 forks source link

Linking errors #141

Closed TaxMachine closed 1 year ago

TaxMachine commented 1 year ago

its most probably a user issue but im clueless of what I'm suppose to do because of the lack of good documentation. I am trying to use your library from vcpkg and I get this error when I compile the code

src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x12a): undefined reference to `__imp_WSACleanup'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x68a): undefined reference to `__imp__ZTVN6mailio7messageE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x70f): undefined reference to `__imp__ZN6mailio4imapC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjNSt6chrono8durationIxSt5ratioILx1ELx1000EEEE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x81b): undefined reference to `__imp__ZN6mailio4imap12authenticateERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES8_NS0_13auth_method_tE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x8bb): undefined reference to `__imp__ZN6mailio4imap6selectERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEb'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x92b): undefined reference to `__imp__ZN6mailio4imap18search_condition_tC1ENS1_8key_typeESt7variantIJSt9monostateNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEENS5_4listISt4pairImSt8optionalImEESaISF_EEEN5boost9gregorian4dateEEE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x99b): undefined reference to `__imp__ZN6mailio4imap6searchERKNSt7__cxx114listINS0_18search_condition_tESaIS3_EEERNS2_ImSaImEEEb'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x9b5): undefined reference to `__imp__ZN6mailio7messageC1Ev'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x9d1): undefined reference to `__imp__ZN6mailio4imap5fetchEmRNS_7messageEbb'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x9df): undefined reference to `__imp__ZNK6mailio7message4fromEv'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x9fa): undefined reference to `__imp__ZNK6mailio4mime7contentB5cxx11Ev'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x13e3): undefined reference to `__imp__ZTVN6mailio4mimeE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x18d6): undefined reference to `__imp__ZN6mailio4imapD1Ev'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text+0x1bef): undefined reference to `__imp__ZN6mailio4imapD1Ev'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text$_ZN6mailio7messageD1Ev[_ZN6mailio7messageD1Ev]+0xd): undefined reference to `__imp__ZTVN6mailio7messageE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text$_ZN6mailio7messageD1Ev[_ZN6mailio7messageD1Ev]+0x771): undefined reference to `__imp__ZTVN6mailio4mimeE'
src/utils/mails/mails.cpp.obj:mails.cpp:(.text.startup+0x2e2): undefined reference to `__imp_WSAStartup'

I have this in my CMakeLists.txt

find_package(mailio CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Boost REQUIRED COMPONENTS system regex date_time)

set(LIB_INCLUDES
        ${CURL_INCLUDE_DIR}
        ${pugixml_INCLUDE_DIR}
        ${argparse_INCLUDE_DIR}
        ${mailio_INCLUDE_DIR}
        ${OPENSSL_INCLUDE_DIR}
        ${Boost_INCLUDE_DIR}
)
set(LINKS
        ${CURL_LIBRARIES}
        pugixml::pugixml
        ${CMAKE_THREAD_LIBS_INIT}
        -lstdc++fs
        ${Boost_LIBRARIES}
        ${OPENSSL_LIBRARIES}
        ${mailio_LIBRARIES}
)

link_directories(
        ${Boost_LIBRARY_DIR}
        ${OPENSSL_LIBRARIES}
        ${CURL_LIBRARY_DIR}
        ${mailio_LIBRARY_DIR}
        -lboost_system
        -lboost_regex
        -lboost_date_time
        -lpthread
        -lcrypto
        -lssl
        -lmailio
        -lwinsock2_32
)

include_directories(project ${LIB_INCLUDES})

target_link_libraries(projetct PUBLIC ${LINKS})

what is the thing im not doing correctly, I tried to do the same as the examples but with no success

karastojko commented 1 year ago

target_link_libraries(projetct PUBLIC ${LINKS}) Is this a typo only here?

TaxMachine commented 1 year ago

not its not even my project name it doesnt matter

karastojko commented 1 year ago

You can use the library without CMake. Just include the headers and link it, like any other Unix library. It would go something like:

g++ -std=c++17 -I ./include/ -I /opt/boost-1.75.0/include/ -L ./build/ -L /opt/boost-1.75.0/lib/ -L /usr/lib/x86_64-linux-gnu/ test.cpp -o test -lboost_system -lboost_regex -lboost_date_time  -lpthread -lcrypto -lssl -lmailio

where the test.cpp is your own example. Ensure that the shared library (libmailio.so) is available.

TaxMachine commented 1 year ago

my project is using CMake I cannot not use it

TaxMachine commented 1 year ago

also I am not on linux

karastojko commented 1 year ago

Here is an extract from one project which uses Mailio:

cmake_minimum_required (VERSION 3.14)
set(PROJ kama)
project (${PROJ} VERSION 0.2.0)
set (CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(PROJSRC
    ${PROJECT_SOURCE_DIR}/source/main.cpp
    ${PROJECT_SOURCE_DIR}/source/configuration.cpp
    ${PROJECT_SOURCE_DIR}/source/db_model.cpp
    ${PROJECT_SOURCE_DIR}/source/sender.cpp
    ${PROJECT_SOURCE_DIR}/source/receiver.cpp
)

set(PROJINC
    ${PROJECT_SOURCE_DIR}/include/configuration.hpp
    ${PROJECT_SOURCE_DIR}/include/db_model.hpp
    ${PROJECT_SOURCE_DIR}/include/sender.hpp
    ${PROJECT_SOURCE_DIR}/include/receiver.hpp
)

add_definitions(-DBOOST_ALL_DYN_LINK)
find_package(Boost COMPONENTS system thread REQUIRED)
include_directories(${Boost_INCLUDE_DIR})

find_package(Threads REQUIRED)
include_directories(include)

find_package(OpenSSL)
include_directories(${OPENSSL_INCLUDE_DIR})

include_directories(${CMAKE_SOURCE_DIR}/libs/mailio/include)
find_library(MAILIO_LIB mailio HINTS ${CMAKE_SOURCE_DIR}/libs/mailio/build)

add_executable(${PROJ} ${PROJSRC} ${PROJINC})
target_link_libraries(${PROJ} ${Boost_LIBRARIES} Threads::Threads ${OPENSSL_LIBRARIES} ${MAILIO_LIB})

Let me know whether it works, since I have stripped the other libraries used by the project.

TaxMachine commented 1 year ago

still doesnt link

karastojko commented 1 year ago

Are you using Windows and MSVC? Did Vcpkg compiled the library into mailio.lib and mailio.dll libraries?

TaxMachine commented 1 year ago

Im using g++ and vcpkg compiled them yes, i tried to include those libs in the cmakelist but it still didn't work

karastojko commented 1 year ago

If the examples and test compile, then the library should be installed. Since your CMake cannot locate the library, you can turn on the verbose mode and check the execution output.

karastojko commented 1 year ago

Cannot be considered as the mailio problem.