Вот код из учебника cpprestSDK от github, который я пытаюсь запустить с помощью qmake.
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include <cpprest/http_listener.h> // HTTP server
#include <cpprest/json.h> // JSON library
#include <cpprest/uri.h> // URI library
#include <cpprest/ws_client.h> // WebSocket client
#include <cpprest/containerstream.h> // Async streams backed by STL containers
#include <cpprest/interopstream.h> // Bridges for integrating Async streams with STL and WinRT streams
#include <cpprest/rawptrstream.h> // Async streams backed by raw pointer to memory
#include <cpprest/producerconsumerstream.h>
#include <pplx/pplx.h>
#include <pplx/threadpool.h>
#include <pplx/pplxcancellation_token.h>
#include <pplx/pplxlinux.h>
#include <cpprest/http_msg.h>
using namespace utility; // Common utilities like string conversions
using namespace web; // Common features like URIs.
using namespace web::http; // Common HTTP functionality
using namespace web::http::client; // HTTP client features
using namespace concurrency::streams; // Asynchronous streams
int main()
{
auto fileStream = std::make_shared<ostream>();
// Open stream to output file.
pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
{
*fileStream = outFile;
// Create http_client to send the request.
http_client client(U("http://www.bing.com/"));
// Build request URI and start the request.
uri_builder builder(U("/search"));
builder.append_query(U("q"), U("cpprestsdk github"));
return client.request(methods::GET, builder.to_string());
})
// Handle response headers arriving.
.then([=](http_response response)
{
printf("Received response status code:%u\n", response.status_code());
// Write response body into the file.
return response.body().read_to_end(fileStream->streambuf());
})
// Close the file stream.
.then([=](size_t)
{
return fileStream->close();
});
// Wait for all the outstanding I/O to complete and handle any exceptions
try
{
requestTask.wait();
}
catch (const std::exception &e)
{
printf("Error exception:%s\n", e.what());
}
return 0;
}
мой .pro-файл
TEMPLATE = app
CONFIG += console c++11
CONFIG -= app_bundle
CONFIG -= qt
SOURCES += \
main.cpp
QMAKE_CXXFLAGS += -std=gnu++11
LIBS += -pthread
Я могу запустить этот код в коде VS с использованием заданных флагов: -lcpprest -lssl -lcrypto -lboost_system -pthread, но qt выдает ошибку, отображаемую ниже
Я не уверен, как я могу сказать qt выполнить код с этими флагами. Это мой вывод компиляции:
g++ -c -pipe -std=gnu++11 -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../../lafayette53/testrest -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o main.o ../../lafayette53/testrest/main.cpp
g++ -c -pipe -std=gnu++11 -g -std=gnu++11 -Wall -W -fPIC -DQT_QML_DEBUG -I../../lafayette53/testrest -I. -I/usr/lib64/qt5/mkspecs/linux-g++ -o server.o ../../lafayette53/testrest/server.cpp
g++ -o testrest main.o server.o -pthread
/usr/bin/ld: main.o: in function `main::{lambda(Concurrency::streams::basic_ostream<unsigned char>)#1}::operator()(Concurrency::streams::basic_ostream<unsigned char>) const':
/home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:32: undefined reference to `web::uri::uri(char const*)'
/usr/bin/ld: /home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:32: undefined reference to `web::http::client::http_client::http_client(web::uri const&)'
/usr/bin/ld: /home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:35: undefined reference to `web::uri::uri(char const*)'
/usr/bin/ld: /home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:37: undefined reference to `web::uri_builder::to_string[abi:cxx11]() const'
/usr/bin/ld: /home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:37: undefined reference to `web::http::methods::GET[abi:cxx11]'
/usr/bin/ld: /home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:32: undefined reference to `web::http::client::http_client::~http_client()'
/usr/bin/ld: /home/leksoBor/Desktop/CS205/build-lafayette53-Desktop-Debug/testrest/../../lafayette53/testrest/main.cpp:32: undefined reference to `web::http::client::http_client::~http_client()'
/usr/bin/ld: main.o: in function `pplx::details::recursive_lock_impl::lock()':
/usr/local/include/pplx/pplxlinux.h:158: undefined reference to `pplx::details::platform::GetCurrentThreadId()'
/usr/bin/ld: main.o: in function `pplx::details::recursive_lock_impl::unlock()':
/usr/local/include/pplx/pplxlinux.h:174: undefined reference to `pplx::details::platform::GetCurrentThreadId()'
/usr/bin/ld: main.o: in function `pplx::details::_CancellationTokenRegistration::_Invoke()':
/usr/local/include/pplx/pplxcancellation_token.h:178: undefined reference to `pplx::details::platform::GetCurrentThreadId()'
/usr/bin/ld: main.o: in function `pplx::details::_CancellationTokenState::_DeregisterCallback(pplx::details::_CancellationTokenRegistration*)':
/usr/local/include/pplx/pplxcancellation_token.h:467: undefined reference to `pplx::details::platform::GetCurrentThreadId()'
/usr/bin/ld: main.o: in function `pplx::details::_TaskCollectionImpl::_RunTask(void (*)(void*), void*, pplx::details::_TaskInliningMode)':
/usr/local/include/pplx/pplx.h:177: undefined reference to `pplx::get_ambient_scheduler()'
/usr/bin/ld: main.o: in function `pplx::task_options::task_options()':
/usr/local/include/pplx/pplxtasks.h:1233: undefined reference to `pplx::get_ambient_scheduler()'
/usr/bin/ld: main.o: in function `web::http::details::http_msg_base::~http_msg_base()':
/usr/local/include/cpprest/http_msg.h:304: undefined reference to `vtable for web::http::details::http_msg_base'
/usr/bin/ld: main.o: in function `web::http::details::_http_response::_http_response()':
/usr/local/include/cpprest/http_msg.h:502: undefined reference to `web::http::details::http_msg_base::http_msg_base()'
/usr/bin/ld: /usr/local/include/cpprest/http_msg.h:502: undefined reference to `vtable for web::http::details::_http_response'
/usr/bin/ld: main.o: in function `web::http::details::_http_request::~_http_request()':
/usr/local/include/cpprest/http_msg.h:856: undefined reference to `vtable for web::http::details::_http_request'
/usr/bin/ld: main.o: in function `web::http::http_request::set_request_uri(web::uri const&)':
/usr/local/include/cpprest/http_msg.h:981: undefined reference to `web::http::details::_http_request::set_request_uri(web::uri const&)'
/usr/bin/ld: main.o: in function `boost::asio::ssl::detail::openssl_init_base::do_init::~do_init()':
/usr/include/boost/asio/ssl/detail/impl/openssl_init.ipp:90: undefined reference to `CONF_modules_unload'
/usr/bin/ld: main.o: in function `boost::asio::error::detail::ssl_category::message[abi:cxx11](int) const':
/usr/include/boost/asio/ssl/impl/error.ipp:39: undefined reference to `ERR_reason_error_string'
/usr/bin/ld: main.o: in function `web::http::client::http_client::request(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pplx::cancellation_token const&)':
/usr/local/include/cpprest/http_client.h:524: undefined reference to `web::uri::uri(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /usr/local/include/cpprest/http_client.h:525: undefined reference to `web::http::client::http_client::request(web::http::http_request, pplx::cancellation_token const&)'
/usr/bin/ld: main.o: in function `web::uri_builder& web::uri_builder::append_query<char [18]>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char const (&) [18], bool)':
/usr/local/include/cpprest/uri_builder.h:263: undefined reference to `web::uri_builder::append_query_encode_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: /usr/local/include/cpprest/uri_builder.h:265: undefined reference to `web::uri_builder::append_query_no_encode_impl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::_Ios_Openmode, int)':
/usr/local/include/cpprest/filestream.h:726: undefined reference to `_open_fsb_str'
/usr/bin/ld: main.o: in function `void __gnu_cxx::new_allocator<web::http::details::_http_request>::construct<web::http::details::_http_request, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >(web::http::details::_http_request*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&&)':
/usr/include/c++/9/ext/new_allocator.h:147: undefined reference to `web::http::details::_http_request::_http_request(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'
/usr/bin/ld: main.o: in function `web::http::details::_http_response::~_http_response()':
/usr/local/include/cpprest/http_msg.h:499: undefined reference to `vtable for web::http::details::_http_response'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_close_file(Concurrency::streams::details::_file_info*)':
/usr/local/include/cpprest/filestream.h:198: undefined reference to `_close_fsb_nolock'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::flush_internal()':
/usr/local/include/cpprest/filestream.h:703: undefined reference to `_sync_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::size() const':
/usr/local/include/cpprest/filestream.h:122: undefined reference to `_get_size'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::seekpos(std::fpos<__mbstate_t>, std::_Ios_Openmode)':
/usr/local/include/cpprest/filestream.h:629: undefined reference to `_seekrdpos_fsb'
/usr/bin/ld: /usr/local/include/cpprest/filestream.h:633: undefined reference to `_seekwrpos_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::seekoff(long, std::_Ios_Seekdir, std::_Ios_Openmode)':
/usr/local/include/cpprest/filestream.h:655: undefined reference to `_seekrdpos_fsb'
/usr/bin/ld: /usr/local/include/cpprest/filestream.h:657: undefined reference to `_seekrdpos_fsb'
/usr/bin/ld: /usr/local/include/cpprest/filestream.h:659: undefined reference to `_seekrdtoend_fsb'
/usr/bin/ld: /usr/local/include/cpprest/filestream.h:674: undefined reference to `_seekwrpos_fsb'
/usr/bin/ld: /usr/local/include/cpprest/filestream.h:676: undefined reference to `_seekwrpos_fsb'
/usr/bin/ld: /usr/local/include/cpprest/filestream.h:677: undefined reference to `_seekwrpos_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_putc(unsigned char)':
/usr/local/include/cpprest/filestream.h:283: undefined reference to `_putn_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_putn(unsigned char const*, unsigned long)':
/usr/local/include/cpprest/filestream.h:346: undefined reference to `_putn_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_bumpc()::{lambda()#1}::operator()() const':
/usr/local/include/cpprest/filestream.h:396: undefined reference to `_getn_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_nextc()::{lambda()#1}::operator()() const':
/usr/local/include/cpprest/filestream.h:500: undefined reference to `_seekrdpos_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_ungetc()::{lambda()#1}::operator()() const':
/usr/local/include/cpprest/filestream.h:516: undefined reference to `_seekrdpos_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_getn(unsigned char*, unsigned long)::{lambda()#1}::operator()() const':
/usr/local/include/cpprest/filestream.h:553: undefined reference to `_getn_fsb'
/usr/bin/ld: main.o: in function `Concurrency::streams::details::basic_file_buffer<unsigned char>::_getcImpl()':
/usr/local/include/cpprest/filestream.h:451: undefined reference to `_getn_fsb'
collect2: error: ld returned 1 exit status
make: *** [Makefile:262: testrest] Error 1
20:12:49: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project lafayette53 (kit: Desktop)
When executing step "Make"
20:12:49: Elapsed time: 00:00.
Я также запустил его, используя cmake, но мне нужно использовать qmake для моего класса. Есть предложения?