How to Link External libraries in c++(windows 10) using command line? - c++

after google search, I came up with this Solution
g++ finlename.cpp -I{include file directory address} -L{Library file directory address}
-l(linkeroptions)
seems like this doesn't work for me. when I compile using this I get an error stating:- cannot find the headername.h(header file that was included in my program of the external lib).
file:-
#include <iostream>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv)
{
cout << "Hello world!" << endl;
return 0;
}

Related

sublime text3 clang-format fatal error: 'iostream' file not found

When I use clang-format to format my C++ code in sublime text3, I received that error iostream file not found.
#include <iostream>
using namespace std;
int main(int argc, const char *argv[]) {
cout << "HELLO, Captain Teemo!" << endl;
return 0;
}
But I can run the c++ code with Command+B.
I also can compile the c++ code in command line.

Gnuplot & C++: Can't find gnuplot neither in PATH nor in "

I am trying to use Gnuplot on Windows with gnuplot_i.hpp. When I type "gnuplot" into cmd everthing works, so the PATH variable should be set correctly. This is my code:
#include <iostream>
#include "gnuplot_i.hpp"
using std::cout;
using std::endl;
int main(int argc, char* argv[]) {
try {
Gnuplot g1("lines");
} catch (GnuplotException ge) {
cout << ge.what() << endl;
}
return 0;
}
The output is Can't find gnuplot neither in PATH nor in "C:/program files/gnuplot/bin" .
When I add the line
Gnuplot::set_GNUPlotPath("C:/gnuplot/bin/");
it just changes to Can't find gnuplot neither in PATH nor in "".
What am I doing wrong here?
Found the answer myself: For some reason gnuplot_i.hpp expects your exe to be called pgnuplot.exe instead of gnuplot.exe ... Now everything works.

I want to know how to use Xcode properly for C++

I made an Xcode project. Like this:
Mac OS X -> Application -> Command Line Tool
I chose C++
And then I saved it in a folder.
Now I opened it in Xcode, there is a file named main.cpp under the project name title, so I opened that.
So main.cpp contains (location: Desktop/CPP/learn/learn/main.cpp)
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
Now I click on File > New File and I selected C++ file without header, I named it main1.cpp
So that main1.cpp now just has
#include <stdio.h>
I replaced that and made main1.cpp to
#include <iostream>
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "MAIN1DOTCPP!\n";
return 0;
}
Then I ran main1.cpp, And the out put was "Hello World", I have been trying to get the output of the second file, That is "MAIN1DOTCPP" for like 2 hours now, Can someone please help?

Why does this code fail to read Blender's .obj file?

Hi I am trying to read a Wavefront file which was created using Blender. I put a copy of this file into the solution Explorer. When I tried to compile for the first time I got the following message:
fatal error LNK1107: invalid or corrupt file: cannot read at 0x...
It seemed like the compiler confused Blender's .obj files with some other format which also uses the .obj ending. The solution was to exclude the file from the build process in its properties.
Now the application does compile but there is no data displayed like I would expect it. Not sure if this is a code issue.
#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;
void ReadPrintFile(string _fileName)
{
std::string line;
std::ifstream fileStream (_fileName);
if (fileStream.is_open())
{
while (getline(fileStream,line))
{
cout << line << '\n';
}
fileStream.close();
}
else
{
cout << "Unable to read file";
}
}
int _tmain(int argc, _TCHAR* argv[])
{
ReadPrintFile("Drone.obj");
std::cin.get();
return 0;
}
The code does not jump into the else statement. The filestream simply seems to be empty and I am directly forwarded to the cin.get(); statement. I know that there are tons of tutorials on how to parse .OBJ in C++ but I want to understand.
The trick was not to copy the file into the solution explorer but into the project folder.

What does boost::locale::generator need?

I'm pretty new to boost and want to use it's boost::locale to make suitable conversations to lower case. But I've got a link problem with boost::locale::generator. I linked my project with libboost_locale-mt.a and switched header search paths correctly, but it isn't enough for some reason. I'm using Xcode, and I got linking mistake on this code:
#include <boost/locale.hpp>
int main(int argc, const char * argv[])
{
using namespace boost::locale;
using namespace std;
generator gen;
std::locale loc = gen("");
locale::global(loc);
cout.imbue(loc);
cout << "This is lower case " << to_lower("Hello World!") << endl;
return 0;
}