B
B
C++ / C#

How to link dynamic library with cpp code?

I want to use this repo
. I did everything correctly and got the dynamic library .so
But when I compile g++ a.cpp -llibseleniumfrom the same directory where .so is
Not compiled with an error:

[email protected]:~# g++ a.cpp -llibselenium
a.cpp: In function ‘int main(int, char**)’:
a.cpp:12:60: error: no matching function for call to ‘Selenium::Selenium(const char [29])’
   Selenium* s = new Selenium("http://127.0.0.1:4444/wd/hub");
                                                            ^
In file included from a.cpp:1:0:
/usr/local/include/selenium/selenium.hpp:12:4: note: candidate: Selenium::Selenium(std::__cxx11::string, bool)
    Selenium(std::string,bool);
    ^~~~~~~~
/usr/local/include/selenium/selenium.hpp:12:4: note:   candidate expects 2 arguments, 1 provided
/usr/local/include/selenium/selenium.hpp:8:7: note: candidate: Selenium::Selenium(const Selenium&)
 class Selenium {
       ^~~~~~~~
/usr/local/include/selenium/selenium.hpp:8:7: note:   no known conversion for argument 1 from ‘const char [29]’ to
 ‘const Selenium&’
/usr/local/include/selenium/selenium.hpp:8:7: note: candidate: Selenium::Selenium(Selenium&&)
/usr/local/include/selenium/selenium.hpp:8:7: note:   no known conversion for argument 1 from ‘const char [29]’ to
 ‘Selenium&&’


As I understand it, the function declared in the header is not exported from the library during compilation. How to fix it?

code in a.caa from the example:
#include <selenium/selenium.hpp>
#include <iostream>
#include <vector>

using std::string;
using std::cout;
using std::endl;

int main(int argc,char** argv) {
  
  //creates new selenium object with the selenium entry page as argument.
  Selenium* s = new Selenium("http://127.0.0.1:4444/wd/hub"); // ошибка тут

  //creates new selenium session.    
  Session* sess = s->createSession(new Capabilities());

  //goes to the google home page.
  sess->url("http://www.google.com");

  //gets all the links on the page
  std::vector<Element*> links = sess->elements(new ElementQuery(ElementQuery::STRAT_TAG_NAME,"a"));

  //displays the number of links on the google homepage
  cout << "# of links:" << links.size() << endl;

}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-03-26
@wataru

While it seems the error is not with the library. You are using the functions declared in the header incorrectly. Judging by the error messages, the constructor of the Selenium class, in addition to the string, also receives a bool.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question