I'm currently working on a class assignment that requires the use of the CImg library. To be clear, the assignment is not linking the library into the program; The class is using it access the pixel data for later use in the heart of the assignment.
I'm working in Xcode (OS X 10.10). CImg (2.2.2) is installed from homebrew, and I've managed to navigate the weird way Xcode deals with search paths (added the header to the section), and have successfully-ish included CImg.
my full code is as below.
#include <iostream>
#define cimg_display 0 //I don't need X11 at all
#include "CImg.h"
using namespace cimg_library;
int main(int argc, const char * argv[]) {
// insert code here...
std::cout << "Hello, World!\n";
return 0;
}
However, I get 17 Compile-time errors from CImg.h, which are very unusual, and all of the form:
"No member named 't_normal' in the global namespace; did you mean simply 't_normal'?"
Thinking I might have received a bad download, I have attempted to redownload CImg, with no luck. I have also gotten to this same point with non-homebrew versions of CImg.
To verify the download, I also compiled the examples from the command line and they ran perfectly.
Is there a problem with CImg that I'm not aware of, a problem with Xcode that I'm not aware of, or is there something fundamental that I'm missing (definitely an option, my C-style programming is a little rusty) ?
halp pls.
Your code runs fine if you do this:
Create a new Xcode project, with:
type = "Command Line Tool"
language = "C++"
Then go to "Build Settings" and add the path to the directory containing CImg.h to your "User Header Search Paths"
Related
Edit:
This program compiles. It's only when run does it fail to find iostream. I'm using the libclang.dylib that is bundled with Xcode.
I've written a small tool to begin working with libclang. I'm trying to parse TranslationUnits. The following program is saved in the file tool.cpp. Once compiled and run, it tries to parse tool.cpp as a TU. It's failing to get a clean run with default headers as it cannot find iostream on my Mac. After several attempts to supply arguments that point to the file, it still doesn't work. Any ideas?
#include "tool.h"
#include <iostream>
int main(int argc, char* argv[]) {
CXIndex index = clang_createIndex(0,0);
const char *args[] = {
"-I/usr/include",
"-I/usr/local/include",
"-I.",
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
//Should be here
"-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1"
}
;
Output:
tool.cpp 6:10: 'iostream' file not found
I've got the same issue. I am trying to add CPP to iOS Objective-C. It's not working. I found that this is about next "pain" from Apple because they do not use standard C++ library anymore. I've tried everything that mentioned on this site but haven't found any solution:
I'm new to Qt creator. Yesterday, I followed the official instructions to configure OpenCV library but it failed. I tried everything on the Internet but it just didn't work. Detailed are listed as belows:
test code is simple, I only want to ensure whether the library works:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
int main(int argc, char *argv[])
{
cout << "Hello World!" << endl;
return 0;
}
My project configuration is like below :
I thought there might be a problem in debugger. I configure the debugger and I'm quite sure it's ok. The picture is here:
But it just doesn't work. When I click build and run, it says:
C1083: cannot open containing files: "opencv2/opencv.hpp": No such
file or directory.
What's strange is when I include <files> in the editor, the automatic code completion can detect the existence of the OpenCV library and hint after <opencv2/> that there are opencv.hpp, core.hpp .etc. and in the Include Hierarchy, the opencv.hpp exists.
So what might be the problem?
Im attempting to get CImg (1.6.8) to work in XCode (7.2) running OSX 10.11.2
#include <iostream>
#include "CImg.h"
int main(int argc, const char * argv[])
{
std::cout << "Hello, World!\n";
return 0;
}
ERRORS:
Use of undeclared identifier 'LC_COLLATE_MASK'
Unknown type name 'locale_t'; did you mean 'locale'?
Long list of errors all concerning unkown type names , undeclared identifiers and too many arguments given follows.
ERRORS
For simplicity CImg.h and X11 are in the project folder and is an explicit search path but I have various unsolved dependencies:
Is there a general method for adding pretty much any library to integrate in Xcode ?
How and where would these dependencies be resolved?
Additional Info :
The Project settings for include dirs are recursive for the X11 folder.
Have tried it with 32bit and 64bit configs.
Firstly, you need to tell Xcode where your header files are - specifically CImg.h.
To do that, first click the area marked red, then the green then the blue and in the Header Search Paths field, enter the directory that contains the file CImg.h.
Normally you then have to set up the Library Search Paths immediately below, and the libraries to link to. But as CImg is a header-only library, there is no need in this specific case.
Finally, I inserted one line of code to avoid all the X11 stuff since OSX no longer ships with X11 and your code doesn't do any X11 stuff anyway.
#include <iostream>
#define cimg_display 0
#include "CImg.h"
int main(int argc, const char * argv[])
{
std::cout << "Hello, World!\n";
return 0;
}
It now runs fine - as you can see at the foot of the screen capture.
Hope that helps.
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.
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char* argv[]) {
std:: cout<<"hello world";
std::cout<<"i am surprise<"<<std::endl;
return (EXIT_SUCCESS);
}
It is very strange because I am using netbeans in Ubuntu 10.04 and run this code. What happens here really makes me surprised; every line of code is marked with red line. For example:
first line indicates that it can't find indicator iostream or can't find file iostream;
second line can't find file stdlib;
third line unable to resolve identifier std and so on,
but it compiles fine and shows me the result "hello world i am surprise"
Please explain why is this happens?
Your IDE's "on the fly" correction tool might not be working correctly (because of bad settings or because fo bugs). I'm guessing it just don't have the access to the default includes.
Your compiler is a separate tool that have access to the includes so it will compile fine anyway.
Try to set the settings correctly or turn the underlining off, or even switch to a better IDE for C++.
The paths for "Code Assistance" are configured separately from your compiler includes. They are usually set when your tool chain is configured but you can check them from the Tools > Options dialog. If your includes are not in any of the paths listed, you will have to add the path. Below is an example of my configuration:
Tools->Options->Code Assistance->C++ Compiler->add path C:\MinGW\bin.
This solved the problem.