Menu

Compiling library

2013-02-14
2017-12-02
  • Evan Sebire

    Evan Sebire - 2013-02-14

    Hi,
    I'm trying to compile simplexlsx as a library for use in a Qt project and keep getting: \Source\Xlsx\Chartsheet.cpp:106: error: cannot convert 'TCHAR' to 'const wchar_t' for argument '2' to 'size_t wcstombs(char, const wchar_t, size_t)'
    Using mingw32-make 3.81, gcc 4.4.0 under win32.
    Do I need to compile SimpleXlsx as a library first? Are there any instructions to do so?

    Thanks for your hard work

     
  • Evan Sebire

    Evan Sebire - 2013-02-14

    Solved, added "DEFINES += _UNICODE" to my simpleXlsx.pro (Qt) file. Sample application worked fine as did the library if "TEMPLATE = lib" was defined.

    Thanks again

     
  • Pavel Akimov

    Pavel Akimov - 2013-02-16

    Hi!

    Thanks for your feedback

     
  • Eduardo Zacarías B.

    Hi,

    First of all, thanks to Pavel for the good work!
    I wrote a simple Makefile and thought somebody else may find it useful.
    The source files are compiled through implicit rules and the objects are stored separately. The only caveat is that the directories where the .o ("obj_xlsx" and "obj_zip") are stored have to be created manually (only once, though) before compiling.

    # simple makefile for the xlsxwriter, as a library
    
    # declare the flags
    CXXFLAGS = -g -Wall
    LDFLAGSCOMMON = 
    
    # Rules with explicit names. Single entry for the target, will be built also on "make all"
    all : xlsxWrite
    xlsxWrite : libxlsxwriter.so
    
    # ----------- declare the names of the directories. For simplicity, each source directory with its own object directory
    OBJ_DIR_XLSX = obj_xlsx
    OBJ_DIR_ZIP = obj_zip
    SRC_DIR_XLSX = Xlsx
    SRC_DIR_ZIP = Zip
    
    # ----------- make object lists and declare implicit rules for each library. 
    # Objects lists are used in linking. Implicit rules are used to compiled the objects declared in the object list
    # pull all the source files as objects. Separately for both dirs, since I don't know how to concatenate the resulting lists
    SRC_FILES_XLSX := $(shell ls -t $(SRC_DIR_XLSX)/*.cpp )
    SRC_FILES_ZIP := $(shell ls -t $(SRC_DIR_ZIP)/*.cpp )
    
    # relate sources and objects in different directories with rules
    # then, the proper object list needs to be passed to the linker
    
    # compose the list of objects by replacing the source with object directory and extension .cpp to .o
    OBJ_FILES_XLSX = $(subst $(SRC_DIR_XLSX)/,$(OBJ_DIR_XLSX)/,$(subst .cpp,.o,$(SRC_FILES_XLSX)))
    OBJ_FILES_ZIP = $(subst $(SRC_DIR_ZIP)/,$(OBJ_DIR_ZIP)/,$(subst .cpp,.o,$(SRC_FILES_ZIP)))
    
    # Now the rules for building. Separately for each source dir. This declares how each .o is generated from the corresponding .cpp
    $(OBJ_DIR_XLSX)/%.o : $(SRC_DIR_XLSX)/%.cpp
        @echo "   Compiling $<"
        @g++ ${CXXFLAGS} -c $< -o $@
    
    $(OBJ_DIR_ZIP)/%.o : $(SRC_DIR_ZIP)/%.cpp
        @echo "   Compiling $<"
        @g++ ${CXXFLAGS} -c $< -o $@
    
    # declare the cleanup rules. Operate on the object lists
    clean :
        @echo "Doing clean-up"
        @rm -rf *.o *.so $(OBJ_FILES_XLSX) $(OBJ_FILES_ZIP)
    
    # Declare the dependencies
    # will require the .o rather than the .cpp because then it only recompiles the changed objects
    
    # Rules for making the main library, libxlsxwriter.so
    libxlsxwriter.so : $(OBJ_FILES_XLSX) $(OBJ_FILES_ZIP)
        @echo "Linking $@"
        @${CXX} ${CXXFLAGS} -shared ${LDFLAGSCOMMON} -o libxlsxwriter.so $(OBJ_FILES_XLSX) $(OBJ_FILES_ZIP)
    
    
    
    
    
     
  • Pavel Akimov

    Pavel Akimov - 2013-04-01

    Hi Eduardo! Thanks for your concern.

    I`ll make next release include your makefile if you don`t mind, of course, to make it easier to share.

     
  • Eduardo Zacarías B.

    Hi Pavel.

    Not a problem. And please feel free to modify it, if you would like to extend it to include versioning/installing options.

    Thanks!

    Eduardo

     
  • Henrique Aschenbrenner

    Hi, I'm having trouble compiling on windows 10. I have a 64bit system, NetBeans IDE 8.2 x86_64 and CygWin64 installed with all -DEV libraries. But I'm having compiler responses that there are undefined references. I've done everything. Can anyone give me a light? With the makefile of Eduardo Zacarias B. I was able to compile in Debian 9.2.1 32bit successfully. I would also like to know if SimpleXlsx is able to create a table with more than 200,000 rows by 32 columns.

    Thank you, and may the force be with you.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-11-29

    Hi Henrique,

    Please explain your problem, show the compiler output.
    As I understand it, the makefile from Eduardo Zacarias B. is designed only for Unix systems.

    Yes, SimpleXlsx is able to create a table with more than 200,000 rows by 32 columns and Excel 2010 successfully opened the result file.

     
  • Henrique Aschenbrenner

    OK, let's go. I am using the 'Simple.cpp' that was placed in the Samples folder. I created the project in NetBeans. the compiler command is:

    g++ -D_UNICODE -c -O2 -ISource/Xlsx -ISource/XLSXColors -ISource/Zip -std=c++11 -MMD -MP -MF "build/Release/Cygwin64-Windows/main.o.d" -o build/Release/Cygwin64-Windows/main.o main.cpp
    

    The commando command:

    g++ -D_UNICODE -o dist/Release/Cygwin64-Windows/simplexlsx build/Release/Cygwin64-Windows/main.o 
    

    and the output of the results of the whole task:

    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text$_ZN10SimpleXlsx10CWorksheet7AddCellEPKcm[_ZN10SimpleXlsx10CWorksheet7AddCellEPKcm]+0x29): undefined reference to `SimpleXlsx::CWorksheet::AddCell(std::string const&, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text$_ZN10SimpleXlsx10CWorksheet7AddCellEPKcm[_ZN10SimpleXlsx10CWorksheet7AddCellEPKcm]+0x29): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorksheet::AddCell(std::string const&, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text$_ZN10SimpleXlsx10CWorksheet7AddCellERKSbIwSt11char_traitsIwESaIwEEm[_ZN10SimpleXlsx10CWorksheet7AddCellERKSbIwSt11char_traitsIwESaIwEEm]+0x174): undefined reference to `SimpleXlsx::CWorksheet::AddCell(std::string const&, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text$_ZN10SimpleXlsx10CWorksheet7AddCellERKSbIwSt11char_traitsIwESaIwEEm[_ZN10SimpleXlsx10CWorksheet7AddCellERKSbIwSt11char_traitsIwESaIwEEm]+0x174): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorksheet::AddCell(std::string const&, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x98): undefined reference to `SimpleXlsx::CWorkbook::CWorkbook(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x98): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorkbook::CWorkbook(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x143): undefined reference to `SimpleXlsx::CWorkbook::AddSheet(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::vector<SimpleXlsx::ColumnWidth, std::allocator<SimpleXlsx::ColumnWidth> >&)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x143): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorkbook::AddSheet(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&, std::vector<SimpleXlsx::ColumnWidth, std::allocator<SimpleXlsx::ColumnWidth> >&)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x1bd): undefined reference to `SimpleXlsx::CWorksheet::MergeCells(SimpleXlsx::CellCoord, SimpleXlsx::CellCoord)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x1bd): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorksheet::MergeCells(SimpleXlsx::CellCoord, SimpleXlsx::CellCoord)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x83d): undefined reference to `SimpleXlsx::CWorksheet::AddCell(long, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x83d): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorksheet::AddCell(long, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x8a9): undefined reference to `SimpleXlsx::CWorksheet::AddCell(long, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x8a9): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorksheet::AddCell(long, unsigned long)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x8e5): undefined reference to `SimpleXlsx::CWorkbook::Save(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x8e5): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorkbook::Save(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&)'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x95b): undefined reference to `SimpleXlsx::CWorkbook::~CWorkbook()'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0x95b): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorkbook::~CWorkbook()'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0xa54): undefined reference to `SimpleXlsx::CWorkbook::~CWorkbook()'
    build/Release/Cygwin64-Windows/main.o:main.cpp:(.text.startup+0xa54): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `SimpleXlsx::CWorkbook::~CWorkbook()'
    collect2: error: ld returned 1 exit status
    

    I believe it has something to do with the -D_UNICODE directive, looking at the code I see that it is well used and interferes with the assiature of the methods. But I can not find where to move to fix.

    Thank you, and may the force be with you.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-11-30

    You need to add to the project all files from the SimpleXlsx directory and subdirectories (* .h, * .hpp, * cpp) and than rebuild project. This is due to the fact that SimpleXLSX is not a "header-only" library.

    The _UNICODE directive is needed to Unicode support by the library (see "tchar.h"). If you compile on Windows, then to support Unicode you additionally need UNICODE directive.

     
  • Henrique Aschenbrenner

    Thank you master! A folder was missing to include in the project. But here's the hint for the folks who use CygWin, for Debug mode compilation, the "sys/syscall.h" file is missing, which I could not solve. But I created a linux virtual machine and compiled it remotely. Then everything became clearer. Be sure to include the <cstring> in the PathManager.cpp file.</cstring>

    Thank you, and may the force be with you.

     
  • Alexandr Belyak

    Alexandr Belyak - 2017-12-02

    I was happy to help!
    Thanks for advice about the <cstring> in PathManager.cpp file, I added it.
    Check out the new version of the library.</cstring>

     

Log in to post a comment.