Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ " was not declared in this scope error while using shared library generated by MySQL C API
    primarykey
    data
    text
    <p>I generated a shared library which wraps MySQL C API functions. It has a sample.h and sample.cpp files like this</p> <pre><code>using namespace std; class MysqlInstance { protected: string user; string password; string socket; int port; public: MySqlInstance(string,string,string,port); int connectToDB(); } </code></pre> <p>In sample.cpp</p> <pre><code>MySqlInstance::MySqlInstance(string user,string pass,string sock,int port) { this-&gt;port=port; this-&gt;user=user; this-&gt;password=pass; this-&gt;socket=sock; } MySqlInstance::connectToDB() { //code to load libmysqlclient.so from /usr/lib64 and use mysql_init and mysql_real_connect // functions to connect and "cout" that connection is successful } </code></pre> <p>Used: </p> <ul> <li><p>g++ -fPIC -c sample.cpp <code>mysql_config --cflags</code></p></li> <li><p>g++ -shared -Wl,-soname,libsample.so -o libsample.so sample.o <code>mysql_config --libs</code></p></li> </ul> <p>Now libsample.so is generated and I moved it to /usr/lib Now I created a small cpp file which uses this shared library in the same directory. <strong>usesample.cpp</strong></p> <pre><code>#include "sample.h" using namespace std; int main() { MysqlInstance* object=new MySQlInstance("root","toor","/lib/socket",3306); } </code></pre> <p>Used:</p> <ul> <li>g++ -c usesample.cpp -lsample</li> </ul> <p>It is giving me this error:</p> <blockquote> <p>error: âMysqlInstanceâ was not declared in this scope error: object was not declared in this scope</p> </blockquote> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload