I create projects using C99 in NetBeans. But when I try to include the library math.h, sqrt() and cbrt() won't work. I am on Ubuntu and using Apache NetBeans IDE 11.2. It is updated to NetBeans 8.2 Patch 2.
The steps I do are : File > New Project > C/C++ > C/C++ Application > Finish. The option Create Main File is checked and it is in C99. I then add #include at the beggining of my code, and at each line I use sqrt() I get an error code : Unable to resolve identifier sqrt.
My code is the following :
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char** argv) {
double x = 1.5;
double z;
z = sqrt(x);
return (EXIT_SUCCESS);
}
And I get an error at line 9.
The reason why I want to edit default project properties is because when I add -lm to my project properties, the error remains but at least to project can run. If it is not in project properties, the project will not run.
Related
I have this program it builds but shows some errors in the includes
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
/** These two files are necessary for calling CTOS API **/
#include <ctosapi.h>
/**
** The main entry of the terminal application
**/
int main(int argc,char *argv[])
{
BYTE key;
// TODO: Add your program here //
CTOS_LCDTClearDisplay();
CTOS_LCDTPrintXY(1, 1, "Hello");
CTOS_KBDGet(&key);
exit(0);
}
here's the print of it:
print of netbeans window
Edited:
here's the error:
Cannot find include file <stdlib.h>.
I think I found the problem but how do I solve this
has u can see in the image the system directories that look for includes are wrong because they have "/gneaubi" twice, the question is how do I change this
It seems that problem is coming from Netbeans IDE.
I would suggest to follow this once and check if the problem is rectified.
Right-click your project and go to properties.
In the properties, click run and change the console type to standard output.
P.S: Please provide proper info about the error by hovering mouse on error ballon. Given info is not sufficient currently.
I am using code::blocks IDE which runs on GNU GCC compiler. In my project I want to play a .wav sound file in C. I tried to play a .wav sound file with a function called PlaySound. When I compiled the code code::blocks gave me an error - PlaySoundA not declared. My code is-
#include <stdio.h>
#include <windows.h>
#include <windowsx.h>
#include <mmsystem.h>
int main(int argc, char *argv[])
{
PlaySound("C:\Snakes and Ladders\snake.wav",NULL,SND_SYNC | SND_LOOP | SND_FILENAME);
return 0;
}
I checked my path twice. I read about this function on the internet and as per me I am using it in the correct way.
In Google, I read that the function exists in a file called winmm.lib. So I put a line of code after all the headers. It was-
#pragma comment (lib , "winmm.lib")
I also added the name winmm.lib to the additional dependencies of code::blocks. So now when I compile the code it gives me another error - winmm.lib not found. Can somebody please tell me how to use PlaySound correctly.
Remove the pragma comment
Double the backslashes. The backslash is an escape character
Compile with the winmm library. Using MinGW, the command would look like this:
gcc foo.c -o foo.exe -lwinmm
Go to Settings - compiler... - linker settings. on the right side in other linker option write this:-lwinmm
System-
Windows 8.1 64 bit machine
OpenCV 3.0.0
Visual Studio 12 2013
I have built the openCV 3.0.0 with the contrib modules. However, when I compile this code I get errors.
#include <OpenNI.h> //used for taking in input from xtion pro live
#include <iostream>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\core\core.hpp>
#include <opencv2\features2d\features2d.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d.hpp> // these are the libraries in the new location (they contain SURF implementation)
#include <opencv2/xfeatures2d/nonfree.hpp>
using namespace std;
//using namespace openni;
using namespace cv;
int main(void)
{
//from sample code
int minHessian = 400;
SurfFeatureDetector detector(minHessian);
return 0;
}
The error is-
error C2065: 'SurfFeatureDetector' : undeclared identifier
The syntax to construct a Surf feature detector in OpenCV 3.0 is different from 2.x versions.
Ptr<SURF> surf=SURF::create(minHessian);
std::vector<KeyPoint> keypts;
Mat desc;
surf->detectAndCompute(img,noArray(),keypts,desc);
Apologies if the above example would still throw any errors, I don't have a working version to field test it.
I think for SURF you must use 'extra' modules. Have a look on that: https://github.com/itseez/opencv_contrib/
Basically what you need to do is download the code (opencv_contrib). Add it to the list of modules in the opencv source folder. Then, in cmake you must add the path < opencv_contrib >/modules into EXTRA_MODULES_PATH. Finally, after generate the project via cmake, you will find the xfeatured2d (I think is the one you need) on your opencv solution and you will be able to build it and use them.
In opencv3.0, it combined all library in opencv_world300d.lib (debug) and opencv_world300.lib (release).
For this, you can use #include to instead other include.
On the other hand, they are opencv_world310d.lib (debug) and opencv_world310.lib (release) in opencv3.1.
I recently started SDL2.0 programming.
I did a lot of researches and i tried all but i still get those "undefined reference" errors for all the SDL functions:
undefined reference to `SDL_Init'|
undefined reference to `SDL_GetError'|
undefined reference to `SDL_Quit'|
||=== Build finished: 3 errors, 0 warnings ===|
on that simple test program:
#include <stdlib.h>
#include <stdio.h>
#include "SDL.h"
int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER) != 0) {
fprintf(stderr, "\nUnable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
return 0;
}
If i have to guess the problem occurs due to the wrong command line syntax.
In this case what should be the correct one?
You aren't linking to the SDL libraries correctly.
Add the following lines int Other Linker Option
-lSDL -lSDLmain
mingw32
SDLmain
SDL
Also You need to check setup for how to compile SDL in codeblock
http://wiki.codeblocks.org/index.php?title=Using_SDL_with_Code::Blocks
http://lazyfoo.net/SDL_tutorials/lesson01/windows/codeblocks/
If it's not too late then try from the beginging to how to set up SDL in codeblock and successfully run it? Below link provide you exact steps for it.
http://www.dreamincode.net/forums/topic/57275-setting-up-codeblocks-to-work-with-sdl/
You might have not linked SDL2 correctly to your CodeBlocks project and not referred to SDL2 correctly in your code.
1:
Go to "Linker options" in "Build Options" menu and make sure you have added these library's to your project like this:
Library's to include in linker options
Importent!: save project before running it after adding/changeing library's.
2:
Change:
#include "SDL.h"
to this:
#include <SDL2/SDL.h>
if you still encounter problems compiling and running it, it's most likely either, your SDL2 files not placed correctly in the compiler's folders, or your using an version of gcc with some missing tools.
These Youtube video's explain everything in great detail:
1: https://www.youtube.com/watch?v=x0LUf7Ibpi0
2: https://www.youtube.com/watch?v=EtUw_7CvRRo
I'm new to external static libraries in C, and i'm having trouble adding pnglib (or any library) to Eclipse. Im using Eclipse v3.3.2 with mingw on windows 7 64bit.
I first followed these instructions to install libpng and zlib: http://wiki.openttd.org/Compiling_on_MinGW
Then in Eclipse under C/C++ Build -> Settings ->Tool Settings -> MinGW C Linker -> Libraries
I added: "png" then "z" in Libraries (-l)
and: "C:\MinGW\libpng-1.5.12" then "C:\MinGW\zlib-1.2.7" in the Library search path (-L)
If I execute the simplest code:
#include <stdio.h>
#include <zlib.h>
#include <png.h>
int main(void) {
printf("foo\n");
unsigned char header[8];
//png_sig_cmp(header, 0, 0);
return 0;
}
It works fine, however as soon as i uncomment the function, the code compiles (without error/warning), but does absolutely nothing, (not even the print statement). This happens when I use ANY function from an external library.
I assume it can read the headers but there's funny business with finding function definitions.
I have no idea where i went wrong.
I'm sure I have missed something trivial!