Error importing class C ++

0

I'm trying to use a library in my C ++ project with CMAKE, the problem that the library is loading the System class, not my class that has same name only the namespace that changes. It is as follows:

-ROOT
    main.cpp
    DataBase.cpp
    DataBase.h // Este está com o #include "String.h"
    includes
        String
            includes
                String.h
                RsaString.h
            lib
                libString.a
                libRsaString.a
        mysql
            includes
            windows
            linux
            macos
        sqlite
    CMakeList.txt

My CMake file looks like this:

cmake_minimum_required(VERSION 3.4)
project(DataBase)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")

include_directories(include/mysql/includes)
include_directories(include/sqlite)
include_directories(include/String/includes)

set(SOURCE_FILES main.cpp DataBase.cpp DataBase.h)

add_executable(DataBase ${SOURCE_FILES})

IF (WIN32)
    #WINDOWS
    target_link_libraries(DataBase ${CMAKE_SOURCE_DIR}/include/Mysql/windows/mysqlcppconn-static.lib)
ELSE()
    IF(APPLE)
        #MAC OS
        target_link_libraries(DataBase ${CMAKE_SOURCE_DIR}/include/String/lib/libString.a)
        target_link_libraries(DataBase ${CMAKE_SOURCE_DIR}/include/Mysql/macos/libmysqlcppconn-static.a)
    ELSE()
        #LINUX
        target_link_libraries(DataBase ${CMAKE_SOURCE_DIR}/include/Mysql/linux/libmysqlcppconn-static.a)
    ENDIF()
ENDIF()

Issue 1

Error:

/Applications/Programas/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/pedrosoares/Library/Caches/CLion2016.1/cmake/generated/DataBase-38151ccf/38151ccf/Debug --target all -- -j 4
[ 33%] Building CXX object CMakeFiles/DataBase.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/DataBase.dir/DataBase.cpp.o
In file included from /Users/pedrosoares/ClionProjects/DataBase/DataBase.cpp:5:
In file included from /Users/pedrosoares/ClionProjects/DataBase/DataBase.h:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:436:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:
In file included from /Users/pedrosoares/ClionProjects/DataBase/include/String/includes/string.h:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:265:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:628:
In file included from /Users/pedrosoares/ClionProjects/DataBase/main.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/iostream:38:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/ios:216:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/string:436:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstring:61:
In file included from /Users/pedrosoares/ClionProjects/DataBase/include/String/includes/string.h:9:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/vector:265:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__bit_reference:15:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/algorithm:628:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1565:17: error: no member named 'memcpy' in namespace 'std::__1'; did you mean 'wmemcpy'?
                _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));

If I comment the include_directories (include / String / includes) line, I get the following error:

/Applications/Programas/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/pedrosoares/Library/Caches/CLion2016.1/cmake/generated/DataBase-38151ccf/38151ccf/Debug --target all -- -j 4
Scanning dependencies of target DataBase
[ 33%] Building CXX object CMakeFiles/DataBase.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/DataBase.dir/DataBase.cpp.o
In file included from /Users/pedrosoares/ClionProjects/DataBase/DataBase.cpp:5:
/Users/pedrosoares/ClionProjects/DataBase/DataBase.h:62:17: error: unknown type name 'vector'
        virtual vector< map<std::string, Tigre::String*> > query(std::string query);
                ^
/Users/pedrosoares/ClionProjects/DataBase/DataBase.h:62:23: error: expected member name or ';' after declaration specifiers
        virtual vector< map<std::string, Tigre::String*> > query(std::string query);
        ~~~~~~~~~~~~~~^
2 errors generated.
make[2]: *** [CMakeFiles/DataBase.dir/DataBase.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
In file included from /Users/pedrosoares/ClionProjects/DataBase/main.cpp:2:
/Users/pedrosoares/ClionProjects/DataBase/DataBase.h:62:17: error: unknown type name 'vector'
        virtual vector< map<std::string, Tigre::String*> > query(std::string query);
                ^
/Users/pedrosoares/ClionProjects/DataBase/DataBase.h:62:23: error: expected member name or ';' after declaration specifiers
        virtual vector< map<std::string, Tigre::String*> > query(std::string query);
        ~~~~~~~~~~~~~~^
2 errors generated.
make[2]: *** [CMakeFiles/DataBase.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/DataBase.dir/all] Error 2
make: *** [all] Error 2

But if I besides comment the line and put the complete PATH in the class include it compiles perfectly.

/Applications/Programas/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/pedrosoares/Library/Caches/CLion2016.1/cmake/generated/DataBase-38151ccf/38151ccf/Debug --target all -- -j 4
Scanning dependencies of target DataBase
[ 33%] Building CXX object CMakeFiles/DataBase.dir/main.cpp.o
[ 66%] Building CXX object CMakeFiles/DataBase.dir/DataBase.cpp.o
[100%] Linking CXX executable DataBase
[100%] Built target DataBase

Class thus compiles only without include_directories :

//
// Created by Pedro Soares on 4/24/16.
//

#ifndef DATABASE_DATABASE_H
#define DATABASE_DATABASE_H

#include "exception"
#include <string>
#include "map"
#include "include/String/includes/String.h"

namespace Tigre {
    using namespace std;

    class DataBaseException : public std::exception {
    public:
        /** Constructor (C strings).
         *  @param message C-style string error message.
         *                 The string contents are copied upon construction.
         *                 Hence, responsibility for deleting the \c char* lies
         *                 with the caller.
         */
        explicit DataBaseException(const char* message):
                msg_(message)
        {
        }

        /** Constructor (C++ STL strings).
         *  @param message The error message.
         */
        explicit DataBaseException(const std::string& message):
                msg_(message)
        {}

        /** Destructor.
         * Virtual to allow for subclassing.
         */
        virtual ~DataBaseException() throw (){}

        /** Returns a pointer to the (constant) error description.
         *  @return A pointer to a \c const \c char*. The underlying memory
         *          is in posession of the \c Exception object. Callers \a must
         *          not attempt to free the memory.
         */
        virtual const char* what() const throw (){
            return msg_.c_str();
        }

    protected:
        /** Error message.
         */
        std::string msg_;

    };

    class DataBase {
    public:
        DataBase();
        ~DataBase();

        virtual vector< map<std::string, Tigre::String*> > query(std::string query);
        virtual bool execute(std::string query);
        virtual void close();

    protected:
        virtual bool open(std::string filename);
        virtual bool open();
    };


}


#endif //DATABASE_DATABASE_H

And so it does not compile with and without include_directories

//
// Created by Pedro Soares on 4/24/16.
//

#ifndef DATABASE_DATABASE_H
#define DATABASE_DATABASE_H

#include "exception"
#include <string>
#include "map"
#include "String.h"

namespace Tigre {
    using namespace std;

    class DataBaseException : public std::exception {
    public:
        /** Constructor (C strings).
         *  @param message C-style string error message.
         *                 The string contents are copied upon construction.
         *                 Hence, responsibility for deleting the \c char* lies
         *                 with the caller.
         */
        explicit DataBaseException(const char* message):
                msg_(message)
        {
        }

        /** Constructor (C++ STL strings).
         *  @param message The error message.
         */
        explicit DataBaseException(const std::string& message):
                msg_(message)
        {}

        /** Destructor.
         * Virtual to allow for subclassing.
         */
        virtual ~DataBaseException() throw (){}

        /** Returns a pointer to the (constant) error description.
         *  @return A pointer to a \c const \c char*. The underlying memory
         *          is in posession of the \c Exception object. Callers \a must
         *          not attempt to free the memory.
         */
        virtual const char* what() const throw (){
            return msg_.c_str();
        }

    protected:
        /** Error message.
         */
        std::string msg_;

    };

    class DataBase {
    public:
        DataBase();
        ~DataBase();

        virtual vector< map<std::string, Tigre::String*> > query(std::string query);
        virtual bool execute(std::string query);
        virtual void close();

    protected:
        virtual bool open(std::string filename);
        virtual bool open();
    };


}


#endif //DATABASE_DATABASE_H

My problem is that I do not think it's good to practice for the full path in the library's include, correct? What would be the best way to solve this? For what I read on the internet, the correct thing is to use 'include_directories' but it generates an error.

    
asked by anonymous 24.06.2016 / 18:04

1 answer

0

Peter, the problem occurs because Windows is not case-sensitive, so "string.h" and "String.h" are the same thing. As the default library (std) is a preferential include this is included twice for your code.

To solve the problem, as you mentioned, using the full path is an option. Unfortunately I do not know another option to help you.

It is interesting to note that if your program is compiled on a Unix-like system like Linux, the problem will not occur, due to case insensitivity.

    
01.07.2016 / 09:16