Git Product home page Git Product logo

Comments (9)

vincentlaucsb avatar vincentlaucsb commented on May 18, 2024 1

It's been deleted since the library doesn't use it anymore, but it wasn't a very complicated function.

Here's the original code:

        std::string type_name(const DataType& dtype) {
            switch (dtype) {
            case CSV_STRING:
                return "string";
            case CSV_INT:
                return "int";
            case CSV_LONG_INT:
                return "long int";
            case CSV_LONG_LONG_INT:
                return "long long int";
            case CSV_DOUBLE:
                return "double";
            default:
                return "null";
            }
        };

However, the csv::internals::DataType enum has changed to

    enum DataType {
        UNKNOWN = -1,
        CSV_NULL,   /**< Empty string */
        CSV_STRING, /**< Non-numeric string */
        CSV_INT8,   /**< 8-bit integer */
        CSV_INT16,  /**< 16-bit integer (short on MSVC/GCC) */
        CSV_INT32,  /**< 32-bit integer (int on MSVC/GCC) */
        CSV_INT64,  /**< 64-bit integer (long long on MSVC/GCC) */
        CSV_DOUBLE  /**< Floating point value */
    };

If you wanted to reimplement the type_name function, here's some advice:

  • UNKNOWN should never be returned so you can just ignore it. I just use it to mark strings which haven't been scanned yet.
  • CSV_INT8 is new and corresponds to short integers. Previously ints of this size would just get classified as CSV_INT.
  • CSV_INT16 would be the equivalent of CSV_INT in the previous code.
  • CSV_INT32 is new.
  • CSV_LONG_INT was largely a mistake which is partly which I changed the enum definition. I thought 32-bit ints were long int, which is true for some compilers, but not so for clang, g++, or MSVC.
  • CSV_INT64 would be the equivalent of "long long int"

Lastly, yes num_rows should take the place of correct_rows in that it only counts rows that are the same length as the header row.

I'm going to close this as there's nothing for me to fix, but feel free to ask more questions.

from csv-parser.

CleanHit avatar CleanHit commented on May 18, 2024

Based on your detailed explanation I've ended using this:

#include "csv_statistics_helper.h"

std::string csvStatisticsHelper::type_name(const csv::DataType& dataType) {
    switch (dataType) {
        case csv::CSV_STRING:
            return "String";
        case csv::CSV_INT8:
            return "Integer (8-bit)";
        case csv::CSV_INT16:
            return "Integer (16-bit)";
        case csv::CSV_INT32:
            return "Integer (32-bit)";
        case csv::CSV_INT64:
            return "Integer (64-bit)";
        case csv::CSV_DOUBLE:
            return "Floating point";
        case csv::UNKNOWN:
            return "Unknown type";
        default:
            return "null";
    }
}

The code errors are gone but now I'm having a different problem and maybe you could help me with that too. Let me know If I need to open a different post for that (for future readers).

In my CMakeLists I import the csv-parser using ExternalProject_Add() for portability reasons:

ExternalProject_Add(csv_parser_pack
        GIT_REPOSITORY    https://github.com/vincentlaucsb/csv-parser.git
        GIT_REMOTE_NAME   releases
        GIT_TAG           1.3.0
        #GIT_TAG           1.1.2
        SOURCE_DIR        "${CMAKE_BINARY_DIR}/csv_parser-src"
        BINARY_DIR        "${CMAKE_BINARY_DIR}/csv_parser-src"
        TEST_COMMAND      ""
        GIT_PROGRESS      1
        LOG_DOWNLOAD      1
        LOG_BUILD         1
        LOG_INSTALL       1
        INSTALL_COMMAND ""
        #CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/csv_parser
        #CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/csv_parser-src && ./configure --prefix=${CMAKE_BINARY_DIR}/csv_parser
        )
# Set include csv-parser package
set(csv_parser_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/csv_parser-src/include)
set(csv_parser_LIBS ${CMAKE_BINARY_DIR}/csv_parser-src/internal/libcsv.a) # Added "/internal"' to point to the new location of "libcsv.a"

I use this to link the libraries to the executable:

add_dependencies(hmmenc-client csv_parser_pack)

# Include the package
target_include_directories(hmmenc-client PRIVATE
        ${csv_parser_INCLUDE_DIRS}
        )

# Link the library
target_link_libraries(hmmenc-client
        ${csv_parser_LIBS}
        )

But I'm getting this error on building the project:

gmake[3]: *** No rule to make target 'csv_parser-src/internal/libcsv.a', needed by '../dev/hmmenc_client/bin/hmmenc-client'.  Stop.
gmake[3]: *** Waiting for unfinished jobs....
gmake[2]: *** [CMakeFiles/Makefile2:87: CMakeFiles/hmmenc-client.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:94: CMakeFiles/hmmenc-client.dir/rule] Error 2
gmake: *** [Makefile:118: hmmenc-client] Error 2

I've used set(csv_parser_LIBS ${CMAKE_BINARY_DIR}/csv_parser-src/libcsv.a) with v1.1.2 and it was building fine with the same CMakeLists settings. Do you see if I'm missing something?

from csv-parser.

vincentlaucsb avatar vincentlaucsb commented on May 18, 2024

I see you're using ExternalProject_Add() to grab the package from GitHub. That's fine, and I've always wanted to try that.

But I don't see the point of

set(csv_parser_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/csv_parser-src/include)
set(csv_parser_LIBS ${CMAKE_BINARY_DIR}/csv_parser-src/internal/libcsv.a) # Added "/internal"' to point to the new location of "libcsv.a"

CMake is a cross-platform build system, which means you shouldn't have to add g++ specific details like where libcsv.a is. For instance, on Windows, Visual Studio doesn't even make .a files yet the same CMake config that I use to build on Ubuntu also works for Visual Studio.

Since you're using CMake and this project uses CMake, I don't see why

target_link_libraries(hmmenc-client csv_parser_pack)

wouldn't work

Manually pointing to libcsv.a would make sense if this project didn't use CMake, except this project does.

from csv-parser.

CleanHit avatar CleanHit commented on May 18, 2024

I've found my error, I had to use set(CSV_PARSER_LIBS ${CMAKE_BINARY_DIR}/csv_parser-src/include/internal/libcsv.a) because the .a lib gets created there. This is my full CMakeLists csv-parser relevant part with ExternalProject_Add() and the .a lib definition:

set(CSV_PARSER "csv_parser")
ExternalProject_Add(
        ${CSV_PARSER}
        GIT_REPOSITORY    https://github.com/vincentlaucsb/csv-parser.git
        GIT_REMOTE_NAME   releases
        GIT_TAG           1.3.0
        SOURCE_DIR        "${CMAKE_BINARY_DIR}/${CSV_PARSER}"
        BINARY_DIR        "${CMAKE_BINARY_DIR}/${CSV_PARSER}"
        TEST_COMMAND      ""
        GIT_SHALLOW       ON
        BUILD_ALWAYS      OFF
        GIT_PROGRESS      ON
        LOG_DOWNLOAD      ON
        LOG_BUILD         ON
        LOG_INSTALL       ON
        INSTALL_COMMAND ""
        )
# Set csv-parser lib variable
set(CSV_PARSER_LIBS ${CMAKE_BINARY_DIR}/${CSV_PARSER}/include/internal/libcsv.a)

add_dependencies(hmmenc-client ${CSV_PARSER})

# Include the package
target_include_directories(hmmenc-client PRIVATE
       ${CSV_PARSER}
        )

# Link the library
target_link_libraries(hmmenc-client PRIVATE
        ${CSV_PARSER_LIBS}
        )

If I only use this target_link_libraries(hmmenc-client ${CSV_PARSER}) I get this error:

CMake Error at CMakeLists.txt:228 (target_link_libraries):
  Target "csv_parser" of type UTILITY may not be linked into another target.
  One may link only to INTERFACE, OBJECT, STATIC or SHARED libraries, or to
  executables with the ENABLE_EXPORTS property set.

I have to provide the exact path to libcsv.a. I know that my ExternalProject_Add() and the other related parts are probably not configured optimally, but they work so far. However, I'm having Build problems when trying to clone a version > 1.3.0 and I'll be opening a new thread about it tomorrow.

from csv-parser.

vincentlaucsb avatar vincentlaucsb commented on May 18, 2024

I'd prefer not having a new ticket created for configuration problems, especially platform specific ones. As far as I'm concerned, the library and CMake files work, so there's nothing for me to do.

I'm just not going to spend my time making this library work for every possible combination of operating system and compiler. With that being said, the current CMake files have been successfully tested with Linux and g++ thousands of times.

If you have CMake >= 3.11 I'd recommend doing the following:

include(FetchContent)

FetchContent_Declare(
    csv
    GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser
    GIT_TAG        1.3.3
)

FetchContent_GetProperties(csv)
if(NOT csv_POPULATED)
    FetchContent_Populate(csv)
endif()

add_subdirectory(${csv_SOURCE_DIR} ${csv_BINARY_DIR})
include_directories(${csv_SOURCE_DIR}/include)

add_executable(csv_test ${CMAKE_CURRENT_LIST_DIR}/main.cpp)
target_link_libraries(csv_test csv)

I've tested it, and it works

image

from csv-parser.

CleanHit avatar CleanHit commented on May 18, 2024

I've tired your settings with CMake 3.13 whithout

add_executable(csv_test ${CMAKE_CURRENT_LIST_DIR}/main.cpp)

Because I have my own executble. Now I get this for all the used csv references for my main.cpp:

/usr/bin/ld: CMakeFiles/hmmenc-client.dir/dev/hmmenc_client/main.cpp.o: in function `main':
/CLionProjects/student_research/dev/hmmenc_client/main.cpp:511: undefined reference to `csv::CSVStat::CSVStat(std::basic_string_view<char, std::char_traits<char> >, csv::CSVFormat)'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:512: undefined reference to `csv::CSVStat::get_dtypes() const'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:513: undefined reference to `csv::CSVReader::get_col_names[abi:cxx11]() const'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:516: undefined reference to `csv::get_file_info(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:747: undefined reference to `csv::CSVStat::CSVStat(std::basic_string_view<char, std::char_traits<char> >, csv::CSVFormat)'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:748: undefined reference to `csv::CSVReader::get_col_names[abi:cxx11]() const'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:749: undefined reference to `csv::CSVStat::get_dtypes() const'
/usr/bin/ld: /CLionProjects/student_research/dev/hmmenc_client/main.cpp:838: undefined reference to `csv::CSVReader::CSVReader(std::basic_string_view<char, std::char_traits<char> >, csv::CSVFormat)'

This happens because FetchContent_Declare() add your repository in config time and doesn't create the libcsv.a file that causes the undefined csv::* references. And using target_link_libraries(csv_test csv) generates:

[ 91%] Linking CXX executable ../dev/hmmenc_client/bin/hmmenc-client
/usr/bin/ld: cannot find -lcsv_parser
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/hmmenc-client.dir/build.make:162: ../dev/hmmenc_client/bin/hmmenc-client] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:226: CMakeFiles/hmmenc-client.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:233: CMakeFiles/hmmenc-client.dir/rule] Error 2
gmake: *** [Makefile:157: hmmenc-client] Error 2

from csv-parser.

CleanHit avatar CleanHit commented on May 18, 2024

I've found the problem. I've used:

FetchContent_Declare(
    csv_parser
    GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser
    GIT_TAG        1.3.0
)

Instead of:

FetchContent_Declare(
    csv
    GIT_REPOSITORY https://github.com/vincentlaucsb/csv-parser
    GIT_TAG        1.3.0
)

And it looks like naming the Fetch csv_parser instead of csv is an issue 😕, with csv the libcsv.a is now beeing found. Everything works for v1.3.0 but when I change the version to one grater than v1.3.0 I get:

100%] Linking CXX executable ../dev/hmmenc_client/bin/hmmenc-client
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_format.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZN3csv9CSVFormat9delimiterEc':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_format.cpp:15: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_format.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZN3csv9CSVFormat9delimiterEc':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_format.cpp:15: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_format.cpp.o):(.data+0xdc0): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZN3csv9internals10format_rowERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS7_EESt17basic_string_viewIcS5_E':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_reader.cpp:383: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZN3csv9internals10format_rowERKSt6vectorINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESaIS7_EESt17basic_string_viewIcS5_E':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_reader.cpp:383: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader.cpp.o):(.data+0x2320): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader_internals.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZN3csv9internals15calculate_scoreESt17basic_string_viewIcSt11char_traitsIcEENS_9CSVFormatE':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_reader_internals.cpp:189: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader_internals.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZN3csv9internals15calculate_scoreESt17basic_string_viewIcSt11char_traitsIcEENS_9CSVFormatE':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_reader_internals.cpp:189: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader_internals.cpp.o):(.data+0x15e0): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader_iterator.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZN3csv9CSVReader5beginEv':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_reader_iterator.cpp:56: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader_iterator.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZN3csv9CSVReader5beginEv':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_reader_iterator.cpp:56: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_reader_iterator.cpp.o):(.data+0x3e0): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_row.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZNK3csv6CSVRow15get_string_viewEm':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_row.cpp:183: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_row.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZNK3csv6CSVRow15get_string_viewEm':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_row.cpp:183: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_row.cpp.o):(.data+0xb80): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_stat.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZN3csv7CSVStatC2ESt17basic_string_viewIcSt11char_traitsIcEENS_9CSVFormatE':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_stat.cpp:252: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_stat.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZN3csv7CSVStatC2ESt17basic_string_viewIcSt11char_traitsIcEENS_9CSVFormatE':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_stat.cpp:252: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_stat.cpp.o):(.data+0x2940): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_utility.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZN3csv5parseESt17basic_string_viewIcSt11char_traitsIcEENS_9CSVFormatE':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_utility.cpp:63: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_utility.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZN3csv5parseESt17basic_string_viewIcSt11char_traitsIcEENS_9CSVFormatE':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/csv_utility.cpp:63: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(csv_utility.cpp.o):(.data+0xaa0): undefined reference to `__gcov_merge_add'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(row_buffer.cpp.o): in function `_GLOBAL__sub_I_00100_0__ZNK3csv9internals8ColNames13get_col_namesB5cxx11Ev':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/row_buffer.cpp:99: undefined reference to `__gcov_init'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(row_buffer.cpp.o): in function `_GLOBAL__sub_D_00100_1__ZNK3csv9internals8ColNames13get_col_namesB5cxx11Ev':
CLionProjects/student_research/cmake-build-debug/_deps/csv-src/include/internal/row_buffer.cpp:99: undefined reference to `__gcov_exit'
/usr/bin/ld: _deps/csv-build/include/internal/libcsv.a(row_buffer.cpp.o):(.data+0xe80): undefined reference to `__gcov_merge_add'
collect2: error: ld returned 1 exit status
gmake[3]: *** [CMakeFiles/hmmenc-client.dir/build.make:163: ../dev/hmmenc_client/bin/hmmenc-client] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:227: CMakeFiles/hmmenc-client.dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:234: CMakeFiles/hmmenc-client.dir/rule] Error 2
gmake: *** [Makefile:157: hmmenc-client] Error 2 

from csv-parser.

dhern023 avatar dhern023 commented on May 18, 2024

@CleanHit THat's one of the quircks with FetchContent. You have to make sure your target_link_libraries works with the correct name (I don't know how to describe).
For example. googletest documentation states to use

# Link 3rd party dependencies.
target_link_libraries(${PROJECT_NAME}_test
    csv
    gtest_main # not googletest according to the documentation
    )

from csv-parser.

CleanHit avatar CleanHit commented on May 18, 2024

@dhern023 Thanks for your reply. I'm using this in my private project for this external project for some time now.

message(CHECK_START "Fetching CSV parser")
set(CSV_PARSER "csv")
set(CSV_PARSER_FLAGS "$<$<AND:$<CONFIG:DEBUG>,$<NOT:$<CXX_COMPILER_ID:MSVC>>>:--coverage>")
FetchContent_Declare(
    ${CSV_PARSER}
    GIT_REPOSITORY  https://github.com/vincentlaucsb/csv-parser
    GIT_TAG         2.1.3
    GIT_SHALLOW     ON
)

FetchContent_GetProperties(${CSV_PARSER})
if(NOT ${CSV_PARSER}_POPULATED)
    FetchContent_Populate(${CSV_PARSER})
    add_subdirectory(${${CSV_PARSER}_SOURCE_DIR} ${${CSV_PARSER}_BINARY_DIR})
endif()

If I'm having some problems with external project lib names. I usually look in the _deps/* path for the project to see if there is a DLL or a static / shared LIB file, If not then I look at external project's CMakeLists.txt for any library creation reference definitions and it's possible alias names. By the way this gave me build errors on including csv in my project.

target_link_libraries(${MY_PROJECT_NAME} PRIVATE
    ${CSV_PARSER}
)

I had to use this to make it work

target_include_directories(${MY_PROJECT_NAME} PRIVATE
    ${${CSV_PARSER}_SOURCE_DIR}/include # one can probably also use ${${CSV_PARSER}_SOURCE_DIR}/single_include
)

from csv-parser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.