clang++ compiler not finding header file <mysqlx/xdevapi.h>

I am compiling a dylib with the following command:

clang++ -I/usr/local/mysql-connector-c++-8.0.13-dynamiclib/include -L/usr/local/mysql-connector-c++-8.0.13/lib64/libmysqlcppconn8-static.a MySqlConn.cpp -o libMySql.dylib

I get error

MySqlConn.cpp:2:10: fatal error: 'mysqlx/xdevapi.h' file not found
#include <mysqlx/xdevapi.h>
^~~~~~~~~~~~~~~~~~ 1 error generated.

Why doesn't the compiler find the header file?
Does running this command line print anything?
find /usr/local -name "xdevapi.h" -print

- Is it installed at all?
- Are you looking in the right place?
- Did you spell the path/filename correctly?

Last edited on
Yes, it is installed. When running the command I get:

userMacBook:c++ user$ find /usr/local -name "xdevapi.h" -print
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/xdevapi.h


But also when I run userMacBook:c++ user$ clang++ -v MySqlConn.cpp, I get the following search directories:

#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
MySqlConn.cpp:2:10: fatal error: 'mysqlx/xdevapi.h' file not found
#include <mysqlx/xdevapi.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.


I understand the compiler is not looking at /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/ for the header files, so when I add the -I flag to include the directory where xdevapi.h is, i.e., clang++ -Lusr/local/mysql-connector-c++-8.0.13-dynamiclib/include MySqlConn.cpp -o libMySql.dylib, I still get:

MySqlConn.cpp:2:10: fatal error: 'mysqlx/xdevapi.h' file not found
#include <mysqlx/xdevapi.h>
         ^~~~~~~~~~~~~~~~~~
1 error generated.


Don't know if my sintax for the -L flag is correct, or whether to use the -L flag instead.

-L is for the linker, your program is with the preprocessor (the -I flag)
1
2
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/xdevapi.h  //your find command
/usr/local/mysql-connector-c++-8.0.13-dynamiclib/include  //the parameter you used for the flag 

¿see the difference?
Wow! Thank you for your help! The compiler found the header file but now I get the following errors:

In file included from MySqlConn.cpp:2:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/xdevapi.h:91:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/devapi/common.h:35:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/devapi/../common.h:49:
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:217:62: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
  typename std::enable_if<std::is_unsigned<U>::value>::type* = nullptr
                                                             ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:222:14: warning: alias declarations are a C++11 extension
      [-Wc++11-extensions]
  using UT = typename std::make_unsigned<T>::type;
             ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:228:62: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
  typename std::enable_if<std::is_unsigned<T>::value>::type* = nullptr,
                                                             ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:229:63: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
  typename std::enable_if<!std::is_unsigned<U>::value>::type* = nullptr
                                                              ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:239:63: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
  typename std::enable_if<!std::is_unsigned<T>::value>::type* = nullptr,
                                                              ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:240:63: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
  typename std::enable_if<!std::is_unsigned<U>::value>::type* = nullptr
                                                              ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:291:29: warning: deleted function definitions are a C++11 extension
      [-Wc++11-extensions]
    nocopy(const nocopy&) = delete;
                            ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:292:40: warning: deleted function definitions are a C++11 extension
      [-Wc++11-extensions]
    nocopy& operator=(const nocopy&) = delete;
                                       ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:326:14: warning: alias declarations are a C++11 extension
      [-Wc++11-extensions]
  using It = typename CONT::iterator;
             ^
In file included from MySqlConn.cpp:2:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/xdevapi.h:91:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/devapi/common.h:35:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/devapi/../common.h:50:
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:97:35: warning: 'override' keyword is a C++11 extension
      [-Wc++11-extensions]
  void print(std::ostream&) const override;
                                  ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:100:22: warning: rvalue references are a C++11 extension
      [-Wc++11-extensions]
  Value(Type type, T &&init)
                     ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:155:64: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
    typename std::enable_if<std::is_unsigned<T>::value>::type* = nullptr
                                                               ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:163:65: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
    typename std::enable_if<!std::is_unsigned<T>::value>::type* = nullptr,
                                                                ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:164:64: warning: default template arguments for a function template are
      a C++11 extension [-Wc++11-extensions]
    typename std::enable_if<std::is_integral<T>::value>::type* = nullptr
                                                               ^ ~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:283:10: warning: unelaborated friend declaration is a C++11 extension;
      specify 'class' to befriend 'mysqlx::common::Value_conv' [-Wc++11-extensions]
  friend Value_conv;
         ^
         class
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:286:10: warning: unelaborated friend declaration is a C++11 extension;
      specify 'struct' to befriend 'mysqlx::common::Value::Access' [-Wc++11-extensions]
  friend Access;
         ^
         struct
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:158:7: error: delegating constructors are permitted only in C++11
    : Value(uint64_t(val))
      ^~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:167:7: error: delegating constructors are permitted only in C++11
    : Value(int64_t(val))
      ^~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/value.h:210:10: error: no matching function for call to 'check_num_limits'
    if (!check_num_limits<int64_t>(val))
         ^~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:220:6: note: candidate template ignored: substitution failure
      [with T = long long, U = unsigned long long]: non-type template argument does not refer to any declaration
bool check_num_limits(U val)
     ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:232:6: note: candidate template ignored: requirement
      'std::is_unsigned<long long>::value' was not satisfied [with T = long long, U = unsigned long long]
bool check_num_limits(U val)
     ^
/usr/local/mysql-connector-c++-8.0.13/include/mysqlx/common/util.h:243:6: note: candidate template ignored: substitution failure
      [with T = long long, U = unsigned long long]: non-type template argument does not refer to any declaration
bool check_num_limits(U val)
     ^
In file included from MySqlConn.cpp:2:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/xdevapi.h:91:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/devapi/common.h:35:
In file included from /usr/local/mysql-connector-c++-8.0.13/include/mysqlx/devapi/../common.h:51:


The list goes on declaring
fatal error: too many errors emitted, stopping now [-ferror-limit=]
96 warnings and 20 errors generated.
. Any idea?
You need to compile using at least the C++11 version of the standard. What is the version of your compiler and how are you specifying the standard version to use?

Hi,

Somehow your compiler is not using the C++11 standard or higher. These days the default standard for g++ and clang++ is c++14. Try specifying c++11 or C++14 or C++17 directly, and turn on warnings:

clang++ -std=c++17 -Wall -Wextra -pedantic-errors ...

The ... is for the rest of your compiling command. I specified c++17 because it shouldn't be hard for you to have the latest version of the compiler. You can check the version with clang++ -v. If it is version 7.0 or greater you should be able to use the c++17 standard.
Hi,

I was able to compile by using clang++ -std=c++11, and clang++ -std=c++17. I have version clang-1000.11.45.5:

UserMacBook:c++ user$ clang++ --version
Apple LLVM version 10.0.0 (clang-1000.11.45.5)
Target: x86_64-apple-darwin18.2.0
Thread model: posix

What standard does it use when I don't specify std=c++XX? The full compile command is:

clang++ -std=c++17 -I /usr/local/mysql-connector-c++-8.0.13/include -L /usr/local/mysql-connector-c++-8.0.13/lib64 MySqlConn.cpp -lmysqlcppconn8 -o libMySql

... where I am linking with MySQL library mysqlcppconn8 with flag -l (right?), but when I check directory -L /usr/local/mysql-connector-c++-8.0.13/lib64, there is no mysqlcppconn8.dylib file, but libmysqlcppconn8.dylib. Should I drop the lib initials when I am linking to a library using flag -l?

Thank you.
Last edited on
Should I drop the lib initials when I am linking to a library using flag -l?


Yes. The manual for g++ is worth looking at, clang is the same except for some extensions:

gccmanual wrote:
3.14 Options for Linking
-l library

Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after file foo.o but before bar.o. If bar.o refers to functions in ‘z’, those functions may not be loaded.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with ‘lib’ and ‘.a’ and searches several directories.


Emphasis added by me.

What standard does it use when I don't specify std=c++XX?


As mentioned earlier it is supposed to be c++14, maybe your configuration file for clang has something else in it?

With your compilation command:

Is LibMySql a good name for the executable, it's not a library is it?

Put the -Wall -Wextra -pedantic-errors options in, warnings are your friend, they tell you about problems with your code. The code may compile with warnings but may lead to run time errors. When I am coding, I am not finished until there are no warnings or errors.

clang++ -std=c++17 -Wall -Wextra -pedantic-errors -I /usr/local/mysql-connector-c++-8.0.13/include -L /usr/local/mysql-connector-c++-8.0.13/lib64 MySqlConn.cpp -lmysqlcppconn8 -o MySqlConn
Topic archived. No new replies allowed.