undefined reference to variable name `Conn::field'
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
undefined reference to variable name `Conn::field'
hi to all, I've centos 7 and codeblocks 17 in VM. I am trying to build a program in which i am accessing MySQL database from c++ 11 .
In this following program :-
-------------- Build: Release in cbs (compiler: GNU GCC Compiler)---------------
g++ -L/usr/lib64/mysql -o bin/Release/cbs obj/Release/draw.o obj/Release/getchoice.o obj/Release/main.o obj/Release/product.o obj/Release/stat.o -s -m64 -lmysqlclient -lmysqlclient_r
obj/Release/product.o:(.data+0x0): multiple definition of `menu'
obj/Release/main.o:(.data+0x0): first defined here
obj/Release/stat.o:(.data+0x0): multiple definition of `menu'
obj/Release/main.o:(.data+0x0): first defined here
obj/Release/product.o: In function `product::printDashes(st_mysql_res*)':
product.cpp:(.text+0xa2): undefined reference to `Conn::field'
product.cpp:(.text+0xc7): undefined reference to `Conn::field'
obj/Release/product.o: In function `product::showAllProduct()':
product.cpp:(.text+0x383): undefined reference to `Conn::res'
product.cpp:(.text+0x38f): undefined reference to `Conn::res'
product.cpp:(.text+0x3a3): undefined reference to `Conn::res'
product.cpp:(.text+0x3b2): undefined reference to `Conn::res'
product.cpp:(.text+0x3c1): undefined reference to `Conn::row'
obj/Release/stat.o: In function `Conn::connection()':
stat.cpp:(.text+0x5): undefined reference to `Conn::mysql'
stat.cpp:(.text+0x2a): undefined reference to `Conn::conn'
stat.cpp:(.text+0x5b): undefined reference to `Conn::mysql'
stat.cpp:(.text+0x67): undefined reference to `Conn::conn'
collect2: error: ld returned 1 exit status
Exactly where is Conn::field defined in your source? (Or, alternatively, here is a simpler question: what is the difference between declaration and definition?)
Excellent. Now I would like to ask another question: exactly where is Conn::field defined in your source? (Or, alternatively, here is a simpler question: what is the difference between declaration and definition?)
Most impressive. Now I would like to ask another question: exactly where is Conn::field defined in your source? (Or, alternatively, here is a simpler question: what is the difference between declaration and definition?)
||=== Build: Release in cbs (compiler: GNU GCC Compiler) ===|
/usr/include/mysql/mysql/psi/psi.h|40|error: #error "You must include my_global.h in the code for the build to be correct."|
/usr/include/mysql/mysql/psi/psi.h|40|error: #error "You must include my_global.h in the code for the build to be correct."|
/usr/include/c++/4.8.2/bits/stl_algobase.h|239|error: macro "min" passed 3 arguments, but takes just 2|
/usr/include/c++/4.8.2/bits/stl_algobase.h|260|error: macro "max" passed 3 arguments, but takes just 2|
/usr/include/mysql/mysql/psi/mysql_thread.h||In function ‘int inline_mysql_cond_wait(mysql_cond_t*, mysql_mutex_t*, const char*, uint)’:|
/usr/include/mysql/mysql/psi/mysql_thread.h|1151|error: ‘my_cond_wait’ was not declared in this scope|
/usr/include/mysql/mysql/psi/mysql_thread.h|1162|error: ‘my_cond_wait’ was not declared in this scope|
/usr/include/mysql/mysql/psi/mysql_thread.h||In function ‘int inline_mysql_cond_timedwait(mysql_cond_t*, mysql_mutex_t*, const timespec*, const char*, uint)’:|
/usr/include/mysql/mysql/psi/mysql_thread.h|1188|error: ‘my_cond_timedwait’ was not declared in this scope|
/usr/include/mysql/mysql/psi/mysql_thread.h|1199|error: ‘my_cond_timedwait’ was not declared in this scope|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected unqualified-id before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected initializer before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected unqualified-id before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected initializer before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|239|error: ‘std::min’ declared as an ‘inline’ variable|
/usr/include/c++/4.8.2/bits/stl_algobase.h|239|error: template declaration of ‘const _Tp& std::min’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|242|error: expected primary-expression before ‘if’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|242|error: expected ‘}’ before ‘if’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|244|error: expected unqualified-id before ‘return’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|260|error: ‘max’ declared as an ‘inline’ variable|
/usr/include/c++/4.8.2/bits/stl_algobase.h|260|error: template declaration of ‘const _Tp& max’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|263|error: expected primary-expression before ‘if’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|263|error: expected ‘}’ before ‘if’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|265|error: expected unqualified-id before ‘return’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|266|error: expected declaration before ‘}’ token|
/usr/include/mysql/mysql/psi/psi.h|40|error: #error "You must include my_global.h in the code for the build to be correct."|
/usr/include/c++/4.8.2/bits/stl_algobase.h|239|error: macro "min" passed 3 arguments, but takes just 2|
/usr/include/c++/4.8.2/bits/stl_algobase.h|260|error: macro "max" passed 3 arguments, but takes just 2|
/usr/include/mysql/mysql/psi/mysql_thread.h||In function ‘int inline_mysql_cond_wait(mysql_cond_t*, mysql_mutex_t*, const char*, uint)’:|
/usr/include/mysql/mysql/psi/mysql_thread.h|1151|error: ‘my_cond_wait’ was not declared in this scope|
/usr/include/mysql/mysql/psi/mysql_thread.h|1162|error: ‘my_cond_wait’ was not declared in this scope|
/usr/include/mysql/mysql/psi/mysql_thread.h||In function ‘int inline_mysql_cond_timedwait(mysql_cond_t*, mysql_mutex_t*, const timespec*, const char*, uint)’:|
/usr/include/mysql/mysql/psi/mysql_thread.h|1188|error: ‘my_cond_timedwait’ was not declared in this scope|
/usr/include/mysql/mysql/psi/mysql_thread.h|1199|error: ‘my_cond_timedwait’ was not declared in this scope|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected unqualified-id before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|193|error: expected initializer before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected unqualified-id before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected ‘)’ before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|216|error: expected initializer before ‘const’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|239|error: ‘std::min’ declared as an ‘inline’ variable|
/usr/include/c++/4.8.2/bits/stl_algobase.h|239|error: template declaration of ‘const _Tp& std::min’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|242|error: expected primary-expression before ‘if’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|242|error: expected ‘}’ before ‘if’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|244|error: expected unqualified-id before ‘return’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|260|error: ‘max’ declared as an ‘inline’ variable|
/usr/include/c++/4.8.2/bits/stl_algobase.h|260|error: template declaration of ‘const _Tp& max’|
/usr/include/c++/4.8.2/bits/stl_algobase.h|263|error: expected primary-expression before ‘if’|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
I already included "mysql/my_global.h" but even this problem arised.
Which file were you compiling when you got these error messages? (Note: I'm afraid you're using cmake, or an "IDE" or some other kind of "helping software".)
How are you invoking your compiler? What mysql library are you using?
If you have mysql_config on your system, what is the output of the following commands.
mysql_config --cflags
mysql_config --libs
You appear to be dealing with a variety of problems at once. If you were to start with and get smaller issues resolved before add complexity it might help.
i.e. compile and run this:
Code:
#include <mysql.h>
#include <stdlib.h>
int main(void) {
if (mysql_library_init(0, NULL, NULL)) {
fprintf(stderr, "could not initialize MySQL client library\n");
exit(1);
}
mysql_library_end();
return EXIT_SUCCESS;
}
One thing that jumps out is the sql includes. It looks like you should remove the first path element in them i.e change #include <sql/sql.h> to #include <sql.h>.
On the other hand, you could add pieces into the code you have that compiles - mysql_test - and build it up a piece at a time, making sure you understand what each piece does and making sure it compiles at each step.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.