gcc compile error cv.h not found for Opencv - c++

every time I try to compile a sample program I get cv.h not found, highgui.c not found. I try to go to the includes folder in opencv and did a sudo copy * to usr/includes and did not help much: i got the following output can someone tell me what i do wrong?
stream_server.c:19:25: fatal error: /usr/include/highgui.h: Permission denied
compilation terminated.
uc#uc-HP-Pavilion-dv6-Notebook-PC:~/Desktop$ sudo gcc stream_server.c -o streamserver
stream_server.c: In function ‘quit’:
stream_server.c:174:5: warning: format not a string literal and no format arguments [-Wformat-security]
stream_server.c:177:5: warning: format not a string literal and no format arguments [-Wformat-security]
/tmp/ccVnjC7y.o: In function `cvDecRefData':
stream_server.c:(.text+0xa9a): undefined reference to `cvFree_'
stream_server.c:(.text+0xb22): undefined reference to `cvFree_'
/tmp/ccVnjC7y.o: In function `cvGetRow':
stream_server.c:(.text+0xc39): undefined reference to `cvGetRows'
/tmp/ccVnjC7y.o: In function `cvGetCol':

The first problem you have is that you apparently installed some file without the correct permissions. Since it seems you can use sudo, you might want to fix the permissions on the file:
sudo chmod a+r /usr/include/highgui.h
(similar to other files you don't have read permissions to).
The other problem indicates that you got your code to compile but not to link. This is most like because you either miss the library name entirely or you have it in the wrong location: make sure you use -lhighgui -lcvaux -lcxcore(this is what I gather from the docs; I haven't used this library myself) after any translation unit you provide (e.g., after stream_server.c; this looks suspiciously like a C file, implying a wrong language tag in action).

Related

How to link bullet libraries(from FindBullet.cmake)?

I'm developing a game, and am trying to use bullet. However, (it seems that) I am having trouble linking the bullet libraries. Edit 2: I have my code on github
This is actually my first time using cmake. I have searched through the FindBullet.cmake file, and could find the variable to link libraries(${BULLET_LIBRARIES}), but linking the libraries in the variable didn't do anything.
find_package(Bullet REQUIRED)
include_directories(${BULLET_INCLUDE_DIR})
target_link_libraries(3DPlatformer ${BULLET_LIBRARIES})
I expected the my code to compile but instead I got a bunch of, "undefined refrence to" then whatever function from bullet it read.
edit:
more undefined references to `btAlignedAllocInternal(unsigned long, int)' follow
^ thats what I got a bunch of
collect2: error: ld returned 1 exit status
And that is the last error.
Full Error
libbullet-dev need to be installed.
sudo apt-get install libbullet-dev
My issue is that one of my if statements was broken.
My if statement:
if(USE_SYSTEM_BULLET)
find_package(Bullet REQUIRED)
include_directories(${BULLET_INCLUDE_DIR})
target_link_libraries(3DPlatformer ${BULLET_LIBRARIES} -lGL -lGLU)
else(USE_SYSTEM_BULLET)
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet" )
include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
endif(USE_SYSTEM_BULLET)
was somehow triggering all the code instead of some of it. commenting the code like this:
#if(USE_SYSTEM_BULLET)
find_package(Bullet REQUIRED)
include_directories(${BULLET_INCLUDE_DIR})
target_link_libraries(3DPlatformer ${BULLET_LIBRARIES} -lGL -lGLU)
#else(USE_SYSTEM_BULLET)
# add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet" )
# include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
#endif(USE_SYSTEM_BULLET)
fixed it.

"error: 'avcodec_open' was not declared in this scope" on attempting to compile untrunc

I have a video recorded by a camera that had a power interruption. As a result, the MP4 file with H.264 codec it was making is damaged. I want to repair this file in Ubuntu 14.04.1. One approach I have seen suggested is to use untrunc. I am attempting to compile this but have run into an error I do not know how to address. What I have done so far is as follows:
sudo apt-get install libavformat-dev libavcodec-dev libavutil-dev
git clone https://github.com/ponchio/untrunc.git
cd untrunc/
g++ -o untrunc file.cpp main.cpp track.cpp atom.cpp mp4.cpp -L/usr/local/lib -lavformat -lavcodec -lavutil
On attempting to compile, I am presented with the following error:
track.cpp: In member function 'void Track::parse(Atom*, Atom*)':
track.cpp:217:47: error: 'avcodec_open' was not declared in this scope
if(avcodec_open(codec.context, codec.codec)<0)
Could you suggest a way to address this error?
avcodec_open was deprecated for avcodec_open2. See for instance this note. Reading through the docs for avcodec_open, it appears that the way to do the replacement is to convert:
avcodec_open(a,b);
to
avcodec_open2(a,b,NULL);
This fix is similar to one that was suggested, but not verified in the untrunc library itself, here.
I tried to verify that the fix worked. In practice, it was a single line modification in track.cpp. Take:
if(avcodec_open(codec.context, codec.codec)<0)
and replace it with
if(avcodec_open2(codec.context, codec.codec, NULL)<0)
(on commit 3c708a, this change is on line 218). NOTE: I only verified that the code compiled, not that it actually worked the way it was supposed to (I don't have a broken m4v to test on). Let me know if it works, or if you encounter any other problems.
Not the exact solution for your question (compile error), but possibly the solution for you primary problem (broken mp4): http://untrunc.it/

Suppress g++ warning message "resolving __ZSt4cout" on Windows 7 [duplicate]

I am trying to compile the following program:
#include <iostream>
int main(){
std::cout << "Hello, world!";
return 0;
}
When I compile it, I get this message:
C:\programs>g++ test.cpp
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.
The build succeeds and the executable runs as expected, but this warning still irritates me. I expect a successful build to be completely silent. This message gives the false impression that there's something wrong with my code.
I can silence this error with g++ -Xlinker --enable-auto-import test.cpp, but this is undesirable, as it triples the number of characters I need to type to compile a program.
Questions:
Why does this warning appear for the simplest of programs? i don't expect cryptic warnings when I compile Hello World.
Is it possible to silence this warning without passing the flag to the linker every time? An option in a config file hidden somewhere in c:\mingw, perhaps? Or maybe I missed an "automatically enable auto-import" checkbox during installation?
Possibly Relevant Specs
GCC Version 4.5.0
ld.exe Version 2.20.51.20100613
Windows XP Service Pack 3
I used to face same problem as you do with g++. I solved this irritating problem just now. Here is how I come to the solution, step-by-step:
On Windows, you can create an alias of g++ with all given options which you want to use with g++. Say, for example, you want to create an alias s++ of g++ -enable-auto-import, then you run this on cmd as:
C:\>doskey s++=g++ -enable-auto-import
This creates an alias called s++. But this alias will not take any command line argument, which means, you cannot write this:
C:\>s++ filename.cpp //it is not working
To make it work, if you've to tell the alias to accept command line arguments while creating it, so here is how it is done:
C:\>doskey s++=g++ -enable-auto-import $*
Please note the $* at the right, which indicates that now s++ can take command line argument:
C:\>s++ filename.cpp //yayyyy..its working now, without giving any warnings!
But you may not prefer to create the alias everytime you open cmd. In that case, you can create a shortcut of cmd.
For example, I created a shortcut called Console and in the Target textbox of shortcut window, I wrote this:
C:\WINDOWS\System32\cmd.exe /K doskey s++=g++ -enable-auto-import $*
And since this is too long (horizontally), one screenshot was not able to capture the entire command. I took two screenshots so that you could see yourself how I did it:
Left part of the command
Right part of the command
For more information on creating aliases on windows, see this:
Creating aliases on Windows
I did some reading and it looks like it might be related to the mingw32 dll not having dllimport attributes defined.
Perhaps there is a patch or you can rebuild mingw32 yourself and add them?

Purpose of --enable-auto-import Warning

I am trying to compile the following program:
#include <iostream>
int main(){
std::cout << "Hello, world!";
return 0;
}
When I compile it, I get this message:
C:\programs>g++ test.cpp
Info: resolving std::cout by linking to __imp___ZSt4cout (auto-import)
c:/mingw/bin/../lib/gcc/mingw32/4.5.0/../../../../mingw32/bin/ld.exe: warning: a
uto-importing has been activated without --enable-auto-import specified on the c
ommand line.
This should work unless it involves constant data structures referencing symbols
from auto-imported DLLs.
The build succeeds and the executable runs as expected, but this warning still irritates me. I expect a successful build to be completely silent. This message gives the false impression that there's something wrong with my code.
I can silence this error with g++ -Xlinker --enable-auto-import test.cpp, but this is undesirable, as it triples the number of characters I need to type to compile a program.
Questions:
Why does this warning appear for the simplest of programs? i don't expect cryptic warnings when I compile Hello World.
Is it possible to silence this warning without passing the flag to the linker every time? An option in a config file hidden somewhere in c:\mingw, perhaps? Or maybe I missed an "automatically enable auto-import" checkbox during installation?
Possibly Relevant Specs
GCC Version 4.5.0
ld.exe Version 2.20.51.20100613
Windows XP Service Pack 3
I used to face same problem as you do with g++. I solved this irritating problem just now. Here is how I come to the solution, step-by-step:
On Windows, you can create an alias of g++ with all given options which you want to use with g++. Say, for example, you want to create an alias s++ of g++ -enable-auto-import, then you run this on cmd as:
C:\>doskey s++=g++ -enable-auto-import
This creates an alias called s++. But this alias will not take any command line argument, which means, you cannot write this:
C:\>s++ filename.cpp //it is not working
To make it work, if you've to tell the alias to accept command line arguments while creating it, so here is how it is done:
C:\>doskey s++=g++ -enable-auto-import $*
Please note the $* at the right, which indicates that now s++ can take command line argument:
C:\>s++ filename.cpp //yayyyy..its working now, without giving any warnings!
But you may not prefer to create the alias everytime you open cmd. In that case, you can create a shortcut of cmd.
For example, I created a shortcut called Console and in the Target textbox of shortcut window, I wrote this:
C:\WINDOWS\System32\cmd.exe /K doskey s++=g++ -enable-auto-import $*
And since this is too long (horizontally), one screenshot was not able to capture the entire command. I took two screenshots so that you could see yourself how I did it:
Left part of the command
Right part of the command
For more information on creating aliases on windows, see this:
Creating aliases on Windows
I did some reading and it looks like it might be related to the mingw32 dll not having dllimport attributes defined.
Perhaps there is a patch or you can rebuild mingw32 yourself and add them?

calling sql from C++

my c++ program has sql code in it, and it runs fine on one linux machine but on the other, I get the following error when I compile it
g++ test.cpp -o a -L/usr/lib/mysql -lmysqlclient -lboost_date_time
fatal error: /usr/include/mysql/mysql.h: No such file or directory
compilation terminated.
I have mysql installed but I am obviously missing some step somewhere (on this machine with a new ubuntu installation)
can someone please let me know the fix. thx!
Looks like your computer doesn't have MySQL installed (in which case, install it), or is installed to a location other than /usr/include/mysql/mysql.h (in which case, change your compile command to point at the correct location)
You need to pass the location of mysql include files.
You are passing library location with:
-L/usr/lib/mysql -lmysqlclient.
If you know where mysql headers are you need to pass them to compiler using:
-I/path/to/directory/with/mysql/headers