我需要将我的项目链接到 libmysql.dll 动态库(我需要这样做,因为我将我的项目构建为/ MDd,参考:https://dev.mysql.com/doc/refman/5.6/en/c-api-building-clients.html)
现在棘手的部分是它是导入库(参考:https://msdn.microsoft.com/en-us/library/d14wsce5.aspx)所以还有一个 libmysql.lib 。
我正在使用CMake进行构建:
set(MYSQL_DIR "C:/Program Files/MySQL/MySQL Connector C 6.1"
CACHE PATH "The path to the MySQL C API library")
include_directories(${MYSQL_DIR}/include)
find_library(mysql NAMES libmysql PATHS ${MYSQL_DIR}/lib)
message(STATUS "mysql library: " ${mysql})
CMake找到库 libmysql.lib 但是当我尝试编译时,我得到以下链接器错误:
LINK : fatal error LNK1104: cannot open file 'mysql.lib'
mysql ,您可以查看上面是CMake变量的名称,该变量包含 libmysql.lib 的路径。
我试图直接链接到.dll但它也不起作用,CMake没有找到.dll。
我应该如何继续使用CMake链接到导入库?谢谢你的帮助。
答案 0 :(得分:1)
您需要在#include <string>
#include <type_traits>
#include <vector>
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <boost/spirit/include/phoenix_stl.hpp>
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/karma_symbols.hpp>
#include <boost/phoenix/bind/bind_member_variable.hpp>
#include <boost/fusion/include/define_struct.hpp>
#include <boost/fusion/include/std_pair.hpp>
enum class TableName {
Foo,
Bar
};
using Map = std::map<TableName, std::vector<int>>;
template<typename OutputIterator>
struct TestGrammar : boost::spirit::karma::grammar<OutputIterator, Map()>
{
TestGrammar() : TestGrammar::base_type(testRule)
{
using boost::spirit::karma::duplicate;
using boost::spirit::karma::int_;
using boost::spirit::karma::lit;
using boost::spirit::karma::_a;
using boost::spirit::karma::_1;
using boost::spirit::karma::_val;
using boost::spirit::karma::skip;
using boost::phoenix::ref;
using boost::phoenix::size;
tableNameSymbols.add
(TableName::Foo, "Foo")
(TableName::Bar, "Bar")
;
tableNameRule %= tableNameSymbols;
// Using _a instead of size_ or sym_ does not work... why?
pairRule %= tableNameRule[ref(sym_) = _1] <<
duplicate[
skip[*int_][ref(size_) = size(_1)] <<
lit(" has ") << lit(ref(size_)) << " entries:\n" <<
*(lit('\t') << /* tableNameRule[_1 = ref(sym_)] */ lit("IT") << lit(" has ") << int_ << lit('\n'))
];
testRule = *(pairRule << lit('\n'));
}
boost::spirit::karma::symbols<TableName, const char *> tableNameSymbols;
boost::spirit::karma::rule<OutputIterator, TableName()> tableNameRule;
boost::spirit::karma::rule<OutputIterator, std::pair<TableName, std::vector<int>>()> pairRule;
boost::spirit::karma::rule<OutputIterator, Map()> testRule;
private:
std::size_t size_;
TableName sym_;
};
int main()
{
using namespace boost::spirit::karma;
Map map = {
{TableName::Foo, {1, 5, 7}},
{TableName::Bar, {2}}
};
std::string output;
std::back_insert_iterator<std::string> sink(output);
/*
* The following outputs
Foo has 3 entries:
IT has 1
IT has 5
IT has 7
Bar has 1 entries:
IT has 2
It should output:
Foo has 3 entries:
Foo has 1
Foo has 5
Foo has 7
Bar has 1 entries:
Bar has 2
*/
bool r = generate(
sink,
TestGrammar<std::decay<decltype(sink)>::type>(),
map
);
std::cout << output;
return r == false;
}
中使用find_library()
来电的结果。在您的情况下,它是target_link_libraries()
。