'sqlite3_api' was not declared in this scope - c++

I've been learning sqlite3 programming in C++ for the first time and this error confounds me and my internet searching abilities.
Here is my code, as far as it gets before throwing an error.
#include <iostream>
#include <sqlite3ext.h>
using namespace std;
int main()
{
sqlite3 *database;
int check;
check = sqlite3_open("introdb3.db", &database); //error is here
}
I'm pretty sure that it has something to do with the libraries that are (or aren't) being linked, but I can't figure out how to make it go properly.
I'm on Ubuntu using code::blocks.
Thanks!!

Instead of
#include <sqlite3ext.h>
write
#include <sqlite3.h>
The sqlite3ext.h file is only needed if you are going to write an SQLite extension - a custom function, for example. For regular database access, use sqlite3.h.

Related

Keep MATLAB engine open in C++ dll

I want to create a dll which keeps an instance of the MATLAB engine open for use by other scripts. That is, the goal is to not have to keep initialising and closing the MATLAB instance, which takes time.
For some background, I have a working C++ program which initialises a MATLAB engine and contains a load of functions to do various things in MATLAB. As some kind of minimum example, I have the three scripts below.
header.h
#pragma once
#include "MatlabEngine.hpp"
#include "MatlabDataArray.hpp"
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <tuple>
#pragma comment (lib,"libmat.lib")
#pragma comment (lib,"libmx.lib")
#pragma comment (lib,"libmex.lib")
#pragma comment (lib,"libeng.lib")
// Example function definition
void setWorkingDir(std::unique_ptr<matlab::engine::MATLABEngine>& matlabPtr, std::string dir);
MatlabFunctions.cpp
#include "header.h"
// Example function
void setWorkingDir(std::unique_ptr<matlab::engine::MATLABEngine>& matlabPtr, std::string dir){
std::u16string matlabCommand = matlab::engine::convertUTF8StringToUTF16String("cd '"+dir+"'");
matlabPtr->eval(matlabCommand);
}
Main.cpp
#include "header.h"
int main(){
using namespace matlab::engine;
matlab::data::ArrayFactory factory; // Create MATLAB data array factory
std::unique_ptr<MATLABEngine> matlabPtr = startMATLAB(); // Start MATLAB engine
// Do various functions
}
My goal is to get rid of Main.cpp and create a dll which keeps keeps the MATLAB engine open, allowing the functions in MatlabFunctions.cpp to be run without having to start the MATLAB engine each time.
Is this possible? And if so, how can it be done?
Some people suggested to use IPC here for the task to be done. Using something like COM is not cross-platform and, well, pretty outdated at the moment. As a modern and cross-platform solution, I'd use an actual server application (which will start MATLAB engine and wait for requests) with, for example, gRPC running. Here's tutorial, pretty good one.
Other than that, you can specify your own networking protocol to run your tasks on the server application without the need of IPC, but the gRPC solution works simply out of the box, no bloat coding included.

C++ - Simple hello world doesn't work in vscode

I've just started programming in c++ and I've a problem that is probably really simple but I've been trying to solve it for a long time.
Cout prints all built-in variables but when I try to print a string variable, it doesn't work (it doesn't print anything even if there are other couts with other things to print that aren't strings).
In short, when there's a string variable in the code, nothing works, at least that is what I noticed.
That doesn't print anything
#include <iostream>
#include <string>
using namespace std;
int main() {
string greeting="hello";
cout << greeting;
}
But that works:
cout << "hello";
I've tried the same exact code in online editors and it does work.
EDIT 1:
In the computer's terminal, this is what is shown: procedure entry point is not found ... in the dinamic link library ...
Path:
This is the mingw path: C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin
EDIT 2
Finally solved it. I've copied the libstdc++ and the libgcc to where I have the .exe.Thank you all for your support. Special thanks to #HolyBlackCat.
The solution to errors like "procedure entry point is not found" is:
Make a list of all .dlls located in your compiler's bin directory.
Go through C:\Windows and C:\Windows\System32 and make sure none of those dlls are there. If you find any, move them somewhere else (or delete them).
Add your compiler's bin directory to the PATH, as the first entry.
I should see the whole code, but considering it doesn't work only with a string, probably you didn't use the namespace std:
Try this:
#include <iostream>
using namespace std;
int main()
{
string greeting = "Hello";
cout << greeting;
}
If it doesn't work, show me the whole code and I'll see if I can help!

Weird compiling error with CodeBlocks - c++

that's my first use to code block but it hasn't gone fine ,, i face a really weird problem
i cant even describe it so i will just tell you what's happened.
the problem is that the ide dont compile my project even if the code were correct
its just open a new tab that called "iostream" and the console window appears but empty
why do that happens ?
look to the code which the ide face a problem while compiling it ,, simplest code ever
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
and this is the compiling results...
thats all..
will codeblocks stop annoying me ?
This line is not valid syntax
usingnamespace std;
Those are two separate keywords
using namespace std;
And since you are just starting C++, Lesson 1: Don't do that.

C++ compiler error message

Im still new to programing, ive started a draft project and coppied the code into anther project but when i try to debug i get this error message i dont know whats going on. Can anyone help me please ?
// this is my code
#include "Questions.h"
#include <iostream>
#include <fstream>
using namespace std;
int main(void)
{
ofstream myfile;
myfile.open ("Questions.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
The error says
error C1075:end of file before the left brace '{' at
#questions.cpp(10) was matched
The error message is self explanatory.
Take a look at the code in questions.cpp, where does the main function end? (Keep in mind that the header files are included verbatim, so make sure that the header file has the same number of {'s as it has for }'s, and that they aren't #ifdef'ed out.) The comments provided by Victor Sand, dasblinkenlight, and Hot Licks are all good.
Your code as it stands is not using Questions.h at all (any more, now that you've commented out the majority of the implementation), so try commenting that include out and then testing. If it passes, the problem is in Questions.h.
Your problem is more than likely coming from Questions.h
If you check that file you'll more than likely see no } at the end.

C++: Unable to resolve identifier cout, Netbeans, Ubuntu

I am using C++ on Netbeans 7.1 on Ubuntu 11.04. For some reason, the following code results in the error message "Unable to resolve identifier cout".
#include <iostream>
using namespace std;
int main()
{
std::cout << "Hello,world!\n";
return 0;
}
Any help resolving this problem would be greatly appreciated.
The solution for your problem is at least strange ;)
Once iostream header is added, one has to reparse code. Click right on a project, go to code assistance and click to reparse project. Worked for me.
I was using netbeans for mac.
check whether iostream is really getting included;
i have tried your code on my machine using eclipse cdt it worked fine.so, please check the
includes.
What sort of file is this in? Is it a .h file, or .hpp file? I had this same issue. Netbeans can be ridiculous sometimes with C++. For me, I changed #include <iostream> to #include<iostream.h>
This may seem too simple, but...
In my NetBeans installation, when I go to create a new project, specify C/C++, it brings up a dialog box prompting for "Project Name:", location, folder, makefile name, and then...
a check box for "Create Main File", an edit box with "main" filled in, and to the right of that is a drop down list that reads "C". If you hit Finish, this will create "main.c" (C, but NOT a C++ file). Instead, in the drop down list, select "C++". Then the IDE creates main.cpp, which will be compiled with g++ and will find those includes and functions.
There is a difference between std::cout and cout. You don't currently have std::cout defined in your file. std::cout is a c standard out. In C++ we only need cout to work with iostream.
If you must use a standard c out then do the following:
Add this to the top under iostream
#include <iostream> //Input output stream in C++
#include <cstdlib> //Stands for c standard library
using namespace std;
Your code will now work because:
This change defines std::cout and std::cin among other things. (standard in, standard out respectively.)
However, I'd recommend this alternative if you don't need standard in outs:
Replace std::cout with cout, because cout is defined in iostream in C++. Your program would have worked without the std:: portion of your cin cout commands because you originally included iostream.
Try taking out the using namespace std; - it's generally considered bad form anyway :-)
I'm not sure that will fix the problem but most people either use the namespace or fully qualify things like std::cout. I've never seen code that does both.
The other thing to check is that the iostream header actually is being bought in. In other words, are there any errors on that line. A lot of problems (at least in the Windows world, so it may not necessarily apply to you) seem to be due to faulty path setup in NetBeans.
Hey look at your Output Debug. You may see "no permission". After I changed the file permission of "/YourProjekt/dist/Debug/GNU-Linux/file" to runable and everyone can read and write the error disappeared. (BTW: I had the bug because I was on a NTFS System with my Projekt, it have to be ext partition)
Hope I can help you with that.
Try taking out the std:: next to cout