eclipse c++ in ubuntu - eclipse-cdt

I was trying to run following code in eclipse in ubuntu 12.04 but It keeps giving me error. could you please tell me why this is happening ? Thanks.
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
Symbol 'std' could not be resolved
Symbol 'cout' could not be resolved
Symbol 'endl' could not be resolved

This is the C++ parser of Eclipse who can't find the symbols.
You could add the config to your already created project but it can be painful. So simply create a new C++ project :
File > New > C++ Project
Then :
Pick the type of project you want, like "Executable > Empty Project" (or maybe "Makefile Project > Empty Project") and make sure to select Linux GCC in the Toolchains. This will add all the default includes in the configuration so that the C++ parser finds everything. Click Finish, paste your code in a C++ file and enjoy.
For information, you can see these include paths in the Project Properties > C/C++ General > Paths and Symbols > Includes > GNU C++.

Related

Reference Abaqus C++ API static libraries to read ODB files

I have Abaqus CAE, Visual Studio 2017, Visual C++ compiler installed in my computer. I'm trying to reference Abaqus CAE's static libraries in my Visual Studio C++ project to read my ODB file.
This is the code file that I'm trying to compile & execute :
```
#include "pch.h"
#include <iostream>
#include <odb_API.h>
#include <odb_String.h>
#include <odb_Repository.h>
using namespace std;
int main()
{
cout << "Initializing API"<<endl;
odb_initializeAPI();
odb_String odbFilePath = "C:\\Users\\Dularish\\Desktop\\Temp_Toclear\\Job-1.odb";
try
{
odb_Odb& odb = openOdb(odbFilePath);
odb.close();
}
catch (odb_BaseException& ex)
{
cout << "Exception message : " << ex.UserReport().CStr() << endl;
}
catch (const std::exception& ex)
{
cout << "Default Exception message : " << ex.what() << endl;
}
cout << "Hello World!\n";
odb_finalizeAPI();
return 0;
}
```
Visual Studio Project Settings :
Platform : X64 (I'll not be able to compile with X86)
Configuration Properties > VC ++ Directories > Include Directories : C:\SIMULIA\Abaqus\6.14-3\code\include;$(IncludePath)
Configuration Properties > VC ++ Directories > Library Directories :
C:\SIMULIA\Abaqus\6.14-3\code\lib;$(LibraryPath)
Configuration Properties > Linker > Input > Additional Dependencies :
ABQDMP_Core.lib;
ABQSMAAbuBasicUtils.lib
.... and all the rest of the files present in the directory "C:\SIMULIA\Abaqus\6.14-3\code\lib".
With these settings, I'm able to compile it without any errors, but on execution of exe application,
I'm getting the below error :
"The procedure entry point ?openOdb##YAAEAVodb_Odb##AEBVodb_String##_N1VSMABasStringMode###Z could not be located in the dynamic link library ABQSMAOdbApi.dll"
Error Screenshot
Does it mean that I'm missing a static library containing openOdb method?
I'm trying to connect with people who are already familiar with Abaqus ODB C++ API who could help me on this.
Thanks.
Edit 1 : I don't want to use abaqus make utility because I want to build my own postprocessing application based on .NET platform. The lines "odb_initializeAPI();" and "odb_finalizeAPI();" are the lines which should be used if I want to access Abaqus ODB API outside Abaqus CAE. I'm actually following this page from the scripting documentation "http://130.149.89.49:2080/v2016/books/cmd/default.htm?startat=pt05ch10s07.html"
The other resource that guided me to use this approach : "https://www.reddit.com/r/fea/comments/8oqx5x/setting_up_abaqus_c_interface/"
There are at least two issues with your solution and approach:
The program you write must not contain a C++ main routine, aka the function main. Instead, the entry point for the program must be a function named ABQmain, having the same signature as the regular function main.
You must compile your Abaqus C++ code using the Abaqus make utility. Once you have finished writing your code and would like to compile it, the correct command to use is:
abaqus make job=your_code.cpp
If you have Abaqus on your machine, then you should also have the documentation. The section "Abaqus Scripting User's Guide" contains a section "Using C++ to access an output database." There you can find some examples and the details I've pointed out here. It should be a good starting point for your work.
EDIT: After pointing out that you wish to use the Visual Studio for development and compilation, make sure to check the system requirements for the Abaqus version you are using. Try to use the same Visual Studio C++ compiler as the one used for compiling Abaqus. Simulia is most probably using an older version of the Visual Studio C++ compiler than you are.

Struggling with libssh on Windows

The problem
I'm trying to build a project in Visual Studio 2015 on Win10 that makes use of libssh, but I'm having no luck getting it to work. I feel like I'm losing my mind here. I'm either completely blanking out or missing something incredibly obvious.
I've tried using the installer libssh-0.7.2-msvc.exe from the files section at https://red.libssh.org/projects/libssh/files. I then linked it to a test C++ project in VS2015. Using the sample code I'm able to compile it:
#include <iostream>
#define LIBSSH_STATIC
#include <libssh/libssh.h>
int main() {
std::cout << "Starting libssh test" << std::endl;
ssh_session my_ssh_session = ssh_new();
if (my_ssh_session == NULL) {
std::cout << "Failed to initialize" << std::endl;
}
ssh_free(my_ssh_session);
return 0;
}
(Note: I've tried both #define LIBSSH_STATIC and #define LIBSSH_STATIC 1 based on posts I've seen from my initial search for answers. I've even tried adding it to the preprocessor definitions in project properties.)
I can only compile it if my project is set to 32-bit, but I can't run the resulting executable. Doing so results in an error: "The code execution cannot proceed because ssh.dll was not found. Reinstalling the program may fix this problem." I'm statically linking ssh.lib, though, so I'm not sure why I'm even getting that error.
So I tried compiling libssh myself as 64-bit. It took some more tinkering than I expected (I had some issues with zlib, which eventually I just omitted since it's optional). I can compile my project as a 64-bit executable successfully, but once again, I can't actually run it. I get the same error about ssh.dll being missing.
For the sake of trying it, I removed the LIBSSH_STATIC define and tried to link just to the DLL. Copying the ssh.dll from the libssh distribution into my program folder and trying to run it, I get the error: "The application was unable to start correctly (0xc000007b). Click OK to close the application."
I'm not sure what I'm missing here, but I'm sure it's dumb and I'm overthinking it.
Project settings (all configurations, all platforms)
libssh is installed to G:\Libraries\libssh_0.7.2 on my machine.
Configuration Properties > VC++ Directories > Include Directories
G:\Libraries\libssh_0.7.2\include;$(IncludePath)
Configuration Properties > VC++ Directories > Library Directories
G:\Libraries\libssh_0.7.2\lib;$(LibraryPath)
Configuration Properties > Linker > Input > Additional Dependencies
ssh.lib;%(AdditionalDependencies)
libssh path summary
libssh_0.7.2
bin
ssh.dll
include
libssh
callbacks.h
legacy.h
libssh.h
libsshpp.hpp
server.h
sftp.h
ssh2.h
lib
ssh.lib
Install vkpkg
⊞ Win+X and open the powershell
Input vckpg install libssh:x64-windows
Integrate into Visual Studio: vcpkg integrate install
Then you can include <libssh.h> in Visual Studio.

vs2015 and vc++ external dependencies error on build

i am learning vc++ and i make my first application win32 console and just write simple code and i get 20 error from external files automatic included
i change compile as to c++ and not using precompiled headers but stil have errors
here is my code
#include <iostream>
int main()
{
//cout << "hello !" << endl;
return 0;
}
how can i fix it ?
Edit :
i have win7 and vs2015 perhaps helps
Edit 2:
last picture is for an empty project this one is for a win32 console app
I think you have created a project set to use precompiled header. Can you start with an empty project and add source file?
And don't forget to set "Not using precomplied header" in file option

Simple C++ program using pqxx (postgres)

I'm trying a very basic C++ program using Code::Blocks. I'm on Ubuntu 12.04 and installed pqxx from the software manager. Here's the code.
#include <pqxx/pqxx>
#include <iostream>
using namespace std;
int main()
{
pqxx::connection MyConn ("dbname=dbESM user=postgres");
cout << "Hello world!" << endl;
return 0;
}
But I get the following error on hitting F9 to compile and run:
/usr/include/pqxx/connection.hxx|87|undefined reference to
`pqxx::connectionpolicy::connectionpolicy(std::basic_string, std::allocator > const&)'
The above message is from the file connection.hxx and the line highlighted is this:
explicit connect_direct(const PGSTD::string &opts) : connectionpolicy(opts) {}
The connection.hxx file is not mine - I think it's part of pqxx.
I'm pretty new to this platform so I'm avoiding the terminal to compile code. Any help would be greatly appreciated.
You need to add the reference to the libpqxx library to the project.
Inside Code::blocks, when the project is open, locate Project in the menus, then follow Build options, then open the tab called Linker settings, then hit Add, then enter pqxx.
If you were using the libpq C library instead, the procedure would be identical except the name would be pq.
You need to link against the according library, just #including the header files isn't enough. If available, you could use pkg-config to determine the according libraries. Further, what IDE are you using? Without that, the "on hitting F9" reference is useless. Also, compiling this on the commandline might even be easier, since it is clearer what exactly is happening.

C++ - Using HunSpell 1.3.2 with Visual Studio 2010

My goal is to create a simple Win32 Console application that uses HunSpell to spell-check a word the user has entered.
I tried to follow this codeproject tutorial which is for Visual Studio 2008 and HunSpell 1.2.1.
I don’t want to use the provided code, since I intend to write my own.
Furthermore I want to add HunSpell as a dll, not as a static library.
Following are the steps I took:
Created a Win32 console (empty) project with the name myproject.
Downloaded HunSpell 1.3.2 from SourceForge.org.
Copied hunspell-1.3.2\src\hunspell and win_api to myproject\myproject\HunSpell-Src
Added and converted project libhunspell myproject\myproject\HunSpell-Src\win-api\libhunspell.vcproj
to the solution.
Made my debug build use debug_dll and my release build release_dll of libhunspell in the Configuration Manager.
Rebuilt the libhunspell project, libhunspell.dll is generated in debug_dll and release_dll folders respectively.
Made my console project depend on libhunspell. (Added reference to libhunspell)
Copied dictionary files en_US.aff & en_US.dic to myproject\myproject\HunSpell-Dic after downloading them from SourceForge.org.
I can’t figure out how/where to add the processor define HSPELLEDIT_DLL that is mentioned in the codeproject tutorial.
Following the steps listed under “To use the functionality from the class library in the console application” on MSDN didn’t changed the result.
I want to test it with a program like this:
#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"
using namespace std;
void main()
{
void *spellObj = hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");
char str[60];
cin >> str;
int result = hunspell_spell(spellObj, str);
if(result == 0)
cout << "Spelling error!";
else
cout << "Correct Spelling!";
hunspell_uninitialize(spellObject);
}
VS produces the following error message if I try to compile it:
myproject\myproject\hunspell-src\win_api\hunspelldll.h(34): fatal error C1083: Cannot open include file: 'hunspell.hxx': No such file or directory
Hunspell.hxx is present in myproject\myproject\HunSpell-Src\hunspell. IntelliSense marks the #include "hunspell.hxx" as an error while the tab hasn’t focus with the message “Error: cannot open source file hunspell.hxx”, but after giving focus to it the error disappears.
Thank you for your help.
The preprocessor definition, HSPELLEDIT_DLL, is not needed unless you are going to actually use the codeproject author's custom control. In the case you want to define it (or other preprocessor definitions) refer to /D (Preprocessor Definitions).
Your path strings need to be double \\ instead of single \ escaped and you have some compile issues:
#include <iostream>
#include "HunSpell-Src/win_api/hunspelldll.h"
using namespace std;
void main()
{
Hunspell *spellObj = (Hunspell *)hunspell_initialize("HunSpell-Dic\\en_us.aff", "HunSpell-Dic\\en_us.dic");
// ^change * type ^cast returned void* to type that will be used later
char str[60];
cin >> str;
int result = hunspell_spell(spellObj, str);
if(result == 0)
cout << "Spelling error!";
else
cout << "Correct Spelling!";
hunspell_uninitialize(spellObj /*SpellObject is undefined*/);
// ^use correct variable
}
For Hunspell.hxx, you need to tell your project how to find it. To do this, open your project settings and and the path to Hunspell.hxx to 'Additional Include Directories' under Configuration Properties > C++ > General. Refer to /I (Additional Include Directories).
Based on your directory structure:
Your Project > Properties > Configuration Properties > C++ > General > 'Additional Include Directories' should look like: .\HunSpell-Src\hunspell;%(AdditionalIncludeDirectories)
Your Project > Properties > Configuration Properties > Linker > General > 'Additional Library Directories' should look like: .\Debug_dll\libhunspell;%(AdditionalLibraryDirectories)
You will also need to copy myproject\myproject\Debug_dll\libhunspell\libhunspell.dll to your projects output directory (.\Debug) or your exe will not be able to find it.