Application compiles in Eclipse, but has 'undefined reference errors' in Qt - c++

I am building an application that uses mysql and needs a graphical user interface. Because I am more comfortable with Eclipse, and it seems to have better organization and 'pop-up references', I decided to develop the main engine in Eclipse, and transfer it to Qt (using Qt Creator 3.1.2, based on Qt 5.3.1) for the GUI. The engine compiles in Eclipse fine (and a command-line test in Eclipse runs well), but when I include the files in the Qt project, I get undefined reference errors.
I get an error (undefined reference to 'sql::mysql::get_driver_instance') anywhere I have this code:
sql::mysql::MySQL_Driver* driver = sql::mysql::get_driver_instance();
I have all the relevant headers included (since Eclipse sees no problem with it):
#include "mysql_driver.h"
#include "mysql_connection.h"
#include < cppconn/driver.h>
#include < cppconn/connection.h>
#include < cppconn/statement.h>
#include < cppconn/prepared_statement.h>
#include < cppconn/resultset.h>
#include < cppconn/metadata.h>
#include < cppconn/resultset_metadata.h>
#include < cppconn/exception.h>
#include < cppconn/warning.h>
Sounds like a linker error, but I can't find a place to specify linker options in the Qt options page. I'm using the gcc compiler on Ubuntu 14.04.
Am I forgetting to change a setting somewhere or is it something else?

I figured it out, thanks to this thread. Rather than linking in an options page, I merely had to edit the Qt project (.pro) file. I added the following:
LIBS += -lmysqlcppconn
And it now compiles and runs fine. So the problem was simply I didn't understand how to do the linking.

Related

Problem with WFDB library in C++ project (undefined reference)

I am trying to link PhysioBank data to my Qt program in Windows 7. I followed the instruction from PhysioNet website and WFDB programmer's guide to install the package in MinGW, and tried to link the library to a simple testing program as suggested in the guide (as below). However, problems show up no mater I try with either Qt creator or Dev C++.
As suggested in the guide (p. 9), I copied curl and wfdb folders and headers to the Visual C++ directory that contains "stdio.h", and include signal.c and wfdbio.c as source files. But eventually the Qt compile error message says that "inttype.h" is not found. I guessed this is because Qt uses Visual C++ compiler but not suggested gcc, and required headers are different. But when I turn to try with Dev C++, which uses gcc 4.9.2, other errors still show up, like: "undefined reference to _imp__curl_version". Is this because the compiler is still somewhat different from that used by MinGW? If my guess is right, how could my work be possibly done?
Sorry for any beginner's mistake. Thanks very much for kind reply!
#include <stdio.h>
#include <wfdb/wfdb.h>
int main(void)
{
int i;
WFDB_Sample v[2];
WFDB_Siginfo s[2];
if (isigopen("100s", s,2) < 2)
exit(1);
for (i = 1; i< 10; i++){
if (getvec(v) < 0)
break;
printf("%d\t%d\n",v[0],v[1]);
}
exit(0);
}

OpenCV3.10 core.hpp must be compiled in C++

i have installed OpenCV 3.10 and the linked the opencv_world310.lib to release and opencv_world310d.lib to debug.
Moreover I put the compiler options in search directory to ...opencv\build\include. I got a undefined reference error when i left out #include <opencv2/highgui.hpp. Now that i have included it my code looks like this:
#include <stdio.h>
#include "opencv/cv.h"
#include "opencv/highgui.h"
#include <opencv2/highgui.hpp>
int main(void){
printf("HALLO!");
return 0;
}
When i try to build it core.hpp opens and the error: core.hpp must be compiled in C++ occurs.
I am using the GNU GCC Compiler in Codeblocks.
What should i do to solve the problem?
Check you compiler options. Open CV 3.10 C++ API requires code to be compiled as C++, but not C. You can use answer to "CodeBlocks: change project language c and c++" question to change the options.
Also use the new Open CV 3.10 API
#include <opencv2/opencv.hpp>`
instead of all the other Open CV header files. This header includes core functionality. To enable highgui module you need to define HAVE_OPENCV_HIGHGUI in your project settings.

sdl, sdl2 error: SDL_window (among others) not declared

I have played around with C++ for a while and just recently started to get into SDL and SDL2.
I was able to get the dot demo program to work.
But other programs, such as Lazy Foo' Productions's copied and pasted don't seem to work.
I have both SDL and SDL2 installed (and uninstalled and reinstalled.) I am on Ubuntu 15.04 and I have the IDE CodeBlocks linked (-ISDL2)
The errors are SDL_Window - SDL_WINDOWPOS_UNDEFINED - SDL_WINDOW_SHOWN - SDL_CreateWindow - SDL_GetWindowSurface - SDL_UpdateWindowSurface and finally, SDL_DestroyWindow -- was not declared in this scope.
Also, I include:
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
I'm pretty sure that I don't need all of that location, but it didn't work without it either. One other note, when I type the #includes, CodeBlocks will suggest SDL2/SDL.h but not SDL/SDL.h.
What am I missing?
I don't think I can put Lazy Foo' code here - I didn't get permission...
The code you listed;
#include </usr/include/SDL/SDL.h>
#include </usr/include/SDL2/SDL.h>
#include <stdio.h>
Why don't you change it to
#include <SDL2/SDL.h>
#include <stdio.h>
as the first header is where SDL_CreateWindow and other SDL2 functions are declared?
Also you don't need to include both SDL and SDL2 headers. Indeed that could very well be the source of your problem as you would only need to include the version you're using.
If you're following the tutorials from lazyfoo's site, you can check if the ones you're following are using SDL1.2 or SDL2 from their table of contents, as the site actually have the tutorials for both versions.
UPDATE:
I didn't notice that your platform is a Linux platform. Then it is so much easier to solve your problem. The demo that you followed previously was done using SDL-1.2, whereas the gcc error hinted that you're using SDL-2.0, hence SDL_CreateWindow and other undefined errors. You should install SDL-2.0 library and SDL-2.0 development files (which will provide you with the necessary SDL-2.0 headers). You may refer this to SDL-2.0 packages provided by your platform distribution.
As for the compilation, it'll be the same as the tutorial you've followed with a minor change, instead of gcc sdltest.o -lSDL -o sdltest, you'll issue gcc sdltest.o -lSDL2 -o sdltest to indicate that you're linking your code against SDL2 library.
EDIT
A simple SDL program to test your environment. You can use any of the simpler text editor such as nano or gedit or others to edit this, and run the compilation command above to test your setup.
The simplest way to do this is by copy the code, then from your terminal, issue cat > sdltest.cpp and paste the code, then hit [ENTER] and [CTRL-C] to end it. Then you can issue the compilation command as mentioned previously,g++ sdltest.cpp -lSDL2 -o sdltest.
Code;
#include <SDL2/SDL.h>
#include <stdio.h>
int main()
{
SDL_Window *p;
SDL_Renderer *w;
p = SDL_CreateWindow("Game",SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,800,640,SDL_WINDOW_SHOWN);
w = SDL_CreateRenderer(p, -1, 0);
SDL_RenderClear(w);
SDL_SetRenderDrawColor(w,255,0,0,255);
SDL_Rect Rect = {220,140,200,200};
SDL_RenderFillRect(w,&Rect);
SDL_RenderPresent(w);
SDL_Delay(3000);
SDL_DestroyRenderer(w);
SDL_DestroyWindow(p);
SDL_Quit();
return 0;
}
Hope that helps.

Code-sense in embedXcode doesn't hightlight syntax for the library I've included

Code-sense mostly works-- all of the core Arduino types are hightlighted properly. But no types
referencing the FastLED library are.
My code compiles fine. And, syntax is hightlighted properly in FastLED.h
How can I make use of code-sense in xCode for Arduino libraries?
At the top of my .ino file, I do this
// Core library for code-sense
#include "Wiring.h"
#include "Arduino.h"
// Include application, user and local libraries
#include "LocalLibrary.h"
#include "FastLED.h"
I am running XCode 5.1 on OSX 10.9.2 with embedXcode+ (professional) release 136. I checked out the FastLED_2.1 branch, as master does not support Teensy 3.1, the board I am using.
Solved. It appears that NO libraries listed in USER_LIBS_LIST confer the benefits to code-sense to your main ino file. However, once I moved the FastLED from
/Users/justin/Documents/Arduino/Libraries
to
/Applications/Arduino.app/Contents/Resources/Java/libraries
and restarted XCode, everything works great.
It seems the table for libraries reached an overflow.
WARNING Overflow reached

SFML crashes at first call using Code::Blocks

I am using SFML 1.6 with Code::Blocks 12.11 on a windows 8.1 computer. I have been having problems so I made a very simple test program, which looks like this:
#include <iostream>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
int main(){
std::cout<<"Start"<<std::endl;
sf::Sprite test;
std::cout<<"End"<<std::endl;
return 0;
}
When I try to run this it prints Start, then crashes. I have checked my linker settings and I think they are right because it compiles just fine with no errors or warnings. Is there something I'm missing?
I actually missed the fact that you're running SFML 1.6. I've tried your code with the latest build from GitHub and it runs just fine. Either this is some bug in 1.6 or you're doing something wrong somewhere else (you shouldn't see any program window unless you're creating one yourself).
Try downloading the latest version (2.1) from the downloads page and see whether it crashes as well. Right now I guess it crashes due to the incompatibility mentioned in this question/answer. Try running g++ -v from the command line to determine the exact version of GCC you're running.