I have a simple C++ program that imports cmath.
#include <cmath>
int main() {
return 0;
}
I'm trying to compile it using the following command.
clang++ -o test main.cpp -std=c++14
But, I get the following errors
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:317:9: error:
no member named 'signbit' in the global namespace
using ::signbit;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:318:9: error:
no member named 'fpclassify' in the global namespace
using ::fpclassify;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:319:9: error:
no member named 'isfinite' in the global namespace; did you mean 'finite'?
using ::isfinite;
~~^
/usr/local/include/math.h:749:12: note: 'finite' declared here
extern int finite(double)
^
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:320:9: error:
no member named 'isinf' in the global namespace
using ::isinf;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:321:9: error:
no member named 'isnan' in the global namespace
using ::isnan;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:322:9: error:
no member named 'isnormal' in the global namespace
using ::isnormal;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:323:9: error:
no member named 'isgreater' in the global namespace
using ::isgreater;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:324:9: error:
no member named 'isgreaterequal' in the global namespace
using ::isgreaterequal;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:325:9: error:
no member named 'isless' in the global namespace
using ::isless;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:326:9: error:
no member named 'islessequal' in the global namespace
using ::islessequal;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:327:9: error:
no member named 'islessgreater' in the global namespace
using ::islessgreater;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:328:9: error:
no member named 'isunordered' in the global namespace
using ::isunordered;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:329:9: error:
no member named 'isunordered' in the global namespace
using ::isunordered;
~~^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:335:9: error:
no member named 'abs' in the global namespace; did you mean 'fabs'?
using ::abs;
~~^
/usr/local/include/math.h:417:15: note: 'fabs' declared here
extern double fabs(double);
^
In file included from main.cpp:2:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:640:26: error:
no template named 'numeric_limits'
bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:640:60: error:
no template named 'numeric_limits'
bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:641:18: error:
no template named 'numeric_limits'
int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:641:50: error:
no template named 'numeric_limits'
int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:646:17: error:
no template named 'numeric_limits'
static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
Here are my system specifications.
macOS Catalina Version 10.15.2
Apple clang version 11.0.3 (clang-1103.0.32.29)
Xcode Version 11.4 (11E146) (not sure if this matters)
Thanks for any assistance!
EDIT: Updated to macOS 10.15.4 and Xcode 11.4.1 and still have the same issue
I believe this is answered at Catalina C++: Using <cmath> headers yield error: no member named 'signbit' in the global namespace
The easiest solution seems to be to uninstall the Command Line Tools, which works on Catalina, but I was hitting this on High Sierra, where I resorted to editing /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/cmath
to comment out #include <math.h> and replace it with:
#include</Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/math.h>
I had to do this to get homebrew's Rust (rustc-1.53.0) to compile on High Sierra. Probably a better approach would be to tell cmake:
set(CMAKE_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk)
since it's not usually a great idea to mess with the system-supplied headers.
Related
I am using mac M1 chip.
i am doing bundle install to install the dependency of my service.
One of our ruby package is using protobuf, so i am getting below error while installing package natively.
Clang version installed is already 13+.
My ruby version is 2.6.6.
i tried with clang version below 11, but getting same error.
Anyone can help what is going wrong here?
/opt/homebrew/include/google/protobuf/stubs/port.h:123:2: error: "Protobuf requires at least C++11."
#error "Protobuf requires at least C++11."
^
/opt/homebrew/include/google/protobuf/stubs/port.h:129:26: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using ConstStringParam = const std::string &;
^
/opt/homebrew/include/google/protobuf/stubs/port.h:145:39: error: expected '(' for function-style cast or type construction
static const int64 kint64max = int64_t{0x7FFFFFFFFFFFFFFF};
~~~~~~~^
/opt/homebrew/include/google/protobuf/stubs/port.h:148:42: error: expected '(' for function-style cast or type construction
static const uint64 kuint64max = uint64_t{0xFFFFFFFFFFFFFFFFu};
~~~~~~~~^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:9:
In file included from /opt/homebrew/include/google/protobuf/stubs/common.h:49:
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:165:23: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using traits_type = std::char_traits<char>;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:166:22: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using value_type = char;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:167:19: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using pointer = char*;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:168:25: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_pointer = const char*;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:169:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using reference = char&;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:170:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_reference = const char&;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:171:26: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_iterator = const char*;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:172:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using iterator = const_iterator;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:173:34: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:174:28: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using reverse_iterator = const_reverse_iterator;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:175:21: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using size_type = size_t;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:176:27: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using difference_type = std::ptrdiff_t;
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:182:10: error: unknown type name 'constexpr'
static constexpr size_type kMaxSize =
^
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:182:29: error: expected ';' at end of declaration list
static constexpr size_type kMaxSize =
^
;
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:280:3: warning: explicit conversion functions are a C++11 extension [-Wc++11-extensions]
explicit operator std::string() const { return ToString(); }
^~~~~~~~
/opt/homebrew/include/google/protobuf/stubs/stringpiece.h:187:39: error: use of undeclared identifier 'kMaxSize'
if (PROTOBUF_PREDICT_FALSE(size > kMaxSize)) {
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:9:
/opt/homebrew/include/google/protobuf/stubs/common.h:166:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
auto volatile unused = &var;
^
/opt/homebrew/include/google/protobuf/stubs/common.h:179:36: warning: 'override' keyword is a C++11 extension [-Wc++11-extensions]
const char* what() const throw() override;
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
/Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:17:2: error: This file was generated by an older version of protoc which is
#error This file was generated by an older version of protoc which is
^
/Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:18:2: error: incompatible with your Protocol Buffer headers. Please
#error incompatible with your Protocol Buffer headers. Please
^
/Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:19:2: error: regenerate this file with a newer version of protoc.
#error regenerate this file with a newer version of protoc.
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:22:
In file included from /opt/homebrew/include/google/protobuf/generated_message_util.h:49:
In file included from /opt/homebrew/include/google/protobuf/any.h:37:
In file included from /opt/homebrew/include/google/protobuf/arenastring.h:38:
In file included from /opt/homebrew/include/google/protobuf/stubs/logging.h:36:
/opt/homebrew/include/google/protobuf/stubs/status.h:46:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class StatusCode : int {
^
/opt/homebrew/include/google/protobuf/stubs/status.h:81:43: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]
bool ok() const { return error_code_ == StatusCode::kOk; }
^
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/src/one_quota.cpp:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/include/one_quota.h:1:
In file included from /Users/<username>.rvm/gems/ruby-2.6.6/gems/pipeline-3.2/ext/protobuf/protobuf/Consumer.pb.h:22:
In file included from /opt/homebrew/include/google/protobuf/generated_message_util.h:49:
In file included from /opt/homebrew/include/google/protobuf/any.h:37:
In file included from /opt/homebrew/include/google/protobuf/arenastring.h:40:
In file included from /opt/homebrew/include/google/protobuf/arena.h:55:
/opt/homebrew/include/google/protobuf/arena_impl.h:54:8: error: unknown type name 'constexpr'
inline constexpr size_t AlignUpTo8(size_t n) {
^
/opt/homebrew/include/google/protobuf/arena_impl.h:54:1: warning: inline variables are a C++17 extension [-Wc++17-extensions]
inline constexpr size_t AlignUpTo8(size_t n) {
^
/opt/homebrew/include/google/protobuf/arena_impl.h:54:24: error: expected ';' after top level declarator
inline constexpr size_t AlignUpTo8(size_t n) {
^
;
/opt/homebrew/include/google/protobuf/arena_impl.h:90:30: warning: defaulted function definitions are a C++11 extension [-Wc++11-extensions]
~ArenaMetricsCollector() = default;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:95:10: error: unknown type name 'constexpr'
static constexpr size_t kDefaultStartBlockSize = 256;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:95:26: error: expected ';' at end of declaration list
static constexpr size_t kDefaultStartBlockSize = 256;
^
;
/opt/homebrew/include/google/protobuf/arena_impl.h:96:10: error: unknown type name 'constexpr'
static constexpr size_t kDefaultMaxBlockSize = 8192;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:96:26: error: expected ';' at end of declaration list
static constexpr size_t kDefaultMaxBlockSize = 8192;
^
;
/opt/homebrew/include/google/protobuf/arena_impl.h:98:3: error: unknown type name 'size_t'
size_t start_block_size = kDefaultStartBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:98:27: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
size_t start_block_size = kDefaultStartBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:99:3: error: unknown type name 'size_t'
size_t max_block_size = kDefaultMaxBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:99:25: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
size_t max_block_size = kDefaultMaxBlockSize;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:100:24: error: unknown type name 'size_t'
void* (*block_alloc)(size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:100:32: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
void* (*block_alloc)(size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:101:32: error: unknown type name 'size_t'
void (*block_dealloc)(void*, size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:101:40: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
void (*block_dealloc)(void*, size_t) = nullptr;
^
/opt/homebrew/include/google/protobuf/arena_impl.h:102:44: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
ArenaMetricsCollector* metrics_collector = nullptr;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
25 warnings and 20 errors generated.
make[2]: *** [src/CMakeFiles/Protobuf.dir/one_quota.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/Protobuf.dir/all] Error 2
make: *** [all] Error 2
While looking at Thread and interfaces C++, I noticed something a little strange with my Clang.
I have c++ --version output of
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
Compiling the following
#include <thread>
class Foo {
public:
void operator()() { }
};
int main() {
Foo *foo = new Foo();
std::thread t(foo);
t.join();
delete foo;
}
with c++ thread.cpp yields the following sensible error:
In file included from thread.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:369:5: error: called object type 'Foo *' is not a function or
function pointer
(*__p)();
^~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:377:42: note: in instantiation of function template
specialization 'std::__1::__thread_proxy<Foo *>' requested here
int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Fp>, __p.get());
^
thread.cpp:10:17: note: in instantiation of function template specialization 'std::__1::thread::thread<Foo *>' requested here
std::thread t(foo);
^
1 error generated.
Total sense - Foo * isn't a function pointer.
But, compiling it with c++ -std=c++11 thread.cpp gives this cryptic error:
In file included from thread.cpp:1:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:332:5: error: attempt to use a deleted function
__invoke(_VSTD::move(_VSTD::get<0>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:342:5: note: in instantiation of function template
specialization 'std::__1::__thread_execute<Foo *>' requested here
__thread_execute(*__p, _Index());
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/thread:354:42: note: in instantiation of function template
specialization 'std::__1::__thread_proxy<std::__1::tuple<Foo *> >' requested here
int __ec = pthread_create(&__t_, 0, &__thread_proxy<_Gp>, __p.get());
^
thread.cpp:10:17: note: in instantiation of function template specialization 'std::__1::thread::thread<Foo *&, void>' requested here
std::thread t(foo);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/type_traits:1027:5: note: '~__nat' has been explicitly marked
deleted here
~__nat() = delete;
^
1 error generated.
What's causing this weird error message about a deleted destructor? Should I consider it a bug in Clang to have such an odd message?
Your actual error message is the same in the two cases: whatever template is used to implement std::thread, it cannot be specialized for Foo*.
~__nat() = delete; is only a random difference between the old and new standard, one of the uninteresting things that fail because of the type error.
I'm using gcc.
I want to create a queue of my own datatype.
In the following code, when I declare struct outside main(), it works fine but it gives compile-time errors when that struct is defined inside.
#include <queue>
using namespace std;
int main()
{
struct tempPos {int a; int b;}; //....(1)
queue<tempPos> b; //works only if tempPos is defined outside main
queue<int> x; //works fine anyways
return 0;
}
Following are the errors.
test.cpp: In function ‘int main()’:
test.cpp:10:15: error: template argument for ‘template<class _Tp> class std::allocator’ uses local type ‘main()::tempPos’
test.cpp:10:15: error: trying to instantiate ‘template<class _Tp> class std::allocator’
test.cpp:10:15: error: template argument 2 is invalid
test.cpp:10:18: error: invalid type in declaration before ‘;’ token
Compilation failed.
C++ forbids using locally-defined classes with templates because they have no linkage. The standard says:
14.3.1/2: .A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.
I've found a strange problem during the compile of an example of ffmpeg in Qt Mac.
I have installed the ffmpeg library and I have tested the examples of this with cc and gcc compiler on the terminal, and I don't have any problem in the case of compile and run.
But when I call the library (ffmpeg are C library) in Qt for compile the same code of the example, the g++ compiler give me many error.
I have used this structure in the main.cpp code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
extern "C" {
#include <libavutil/imgutils.h>
#include <libavutil/samplefmt.h>
#include <libavutil/timestamp.h>
#include <libavformat/avformat.h>
}
#include <QDebug>
and the Compile Output gives me:
In file included from ../audvid/main.cpp:7:
/opt/local/include/libavutil/timestamp.h: In function 'char*
av_ts_make_string(char*, int64_t)':
/opt/local/include/libavutil/timestamp.h:48: warning: comparison
between signed and unsigned integer expressions
/opt/local/include/libavutil/timestamp.h:49: error: expected `)'
before 'PRId64' /opt/local/include/libavutil/timestamp.h:49: warning:
spurious trailing '%' in format
/opt/local/include/libavutil/timestamp.h:49: warning: too many
arguments for format /opt/local/include/libavutil/timestamp.h: At
global scope: /opt/local/include/libavutil/timestamp.h:68: error:
'AVRational' has not been declared
/opt/local/include/libavutil/timestamp.h: In function 'char*
av_ts_make_time_string(char*, int64_t, int*)':
/opt/local/include/libavutil/timestamp.h:70: warning: comparison
between signed and unsigned integer expressions
/opt/local/include/libavutil/timestamp.h:71: error: 'av_q2d' was not
declared in this scope ../audvid/main.cpp: In function 'int
decode_packet(int*, int)': ../audvid/main.cpp:50: error: cannot
convert 'AVRational*' to 'int*' for argument '3' to 'char*
av_ts_make_time_string(char*, int64_t, int*)' ../audvid/main.cpp:73:
error: cannot convert 'AVRational*' to 'int*' for argument '3' to
'char* av_ts_make_time_string(char*, int64_t, int*)'
../audvid/main.cpp:75: error: 'struct AVFrame' has no member named
'channels' ../audvid/main.cpp:84: error: 'struct AVFrame' has no
member named 'channels' ../audvid/main.cpp:90: error: 'struct AVFrame'
has no member named 'channels' ../audvid/main.cpp: In function 'int
open_codec_context(int*, AVFormatContext*, AVMediaType)':
../audvid/main.cpp:112: error: 'av_get_media_type_string' was not
declared in this scope ../audvid/main.cpp:123: error:
'av_get_media_type_string' was not declared in this scope
../audvid/main.cpp:129: error: 'av_get_media_type_string' was not
declared in this scope ../audvid/main.cpp: In function 'int
get_format_from_sample_fmt(const char**, AVSampleFormat)':
../audvid/main.cpp:152: warning: comparison between signed and
unsigned integer expressions ../audvid/main.cpp: In function 'int
main(int, char**)': ../audvid/main.cpp:239: error: invalid conversion
from 'void*' to 'uint8_t**' make: *** [main.o] Error 1 make: Leaving
directory
`/Users/polin/Desktop/audvid/audvid-build- Qt_4_8_0_qt_everywhere_opensource_src_4_8_0_tp-Release'
10:44:37: The process "/usr/bin/make" exited with code 2. Error while
building/deploying project audvid (target: Qt 4.8.0
(qt-everywhere-opensource-src-4.8.0-tp)) When executing step 'Make'
I don't understand if I make a mistake in the code or if I must change the Qt compiler? (and I don't know how can do this)
You need to include libavutil/avutil.h before #include <libavutil/imgutils.h>. Also you need to add #include <libavcodec/avcodec.h>
Because ffmpeg is written in pure C. Some C99 design is incompatible with g++ compiler. So one way to solve it is to find where the "wrong" source codes are and replace them with C++ design style.
e.g.
av_get_bytes_per_sample( static_cast<AVSampleFormat>(format) )
#undef av_err2str
#define av_err2str(errnum) \
av_make_error_string((char*)__builtin_alloca(AV_ERROR_MAX_STRING_SIZE), AV_ERROR_MAX_STRING_SIZE, errnum)
#undef av_ts2timestr
#define av_ts2timestr(ts, tb) \
av_ts_make_time_string((char*)__builtin_alloca(AV_TS_MAX_STRING_SIZE), ts, tb)
I'm trying to compile a file with the V8 the JavaScript Engine by Google. I installed scons and have compiled the V8 engine. But, here is where the problem lies, I stay in the V8 directory as they say and make a file named hello_world.cpp with the code:
#include <v8.h>
using namespace v8;
int main(int argc, char* argv[]) {
// Create a stack-allocated handle scope.
HandleScope handle_scope;
// Create a new context.
Persistent<Context> context = Context::New();
// Enter the created context for compiling and
// running the hello world script.
Context::Scope context_scope(context);
// Create a string containing the JavaScript source code.
Handle<String> source = String::New("'Hello' + ', World!'");
// Compile the source code.
Handle<Script> script = Script::Compile(source);
// Run the script to get the result.
Handle<Value> result = script->Run();
// Dispose the persistent context.
context.Dispose();
// Convert the result to an ASCII string and print it.
String::AsciiValue ascii(result);
printf("%s\n", *ascii);
return 0;
}
Then I compile using gcc hello_world.cpp -o libv8.a. But, when I compile it I get a skew of errors:
hello_world.cpp:1:16: error: v8.h: No such file or directory
hello_world.cpp:3: error: ‘v8’ is not a namespace-name
hello_world.cpp:3: error: expected namespace-name before ‘;’ token
hello_world.cpp: In function ‘int main(int, char**)’:
hello_world.cpp:8: error: ‘HandleScope’ was not declared in this scope
hello_world.cpp:8: error: expected `;' before ‘handle_scope’
hello_world.cpp:11: error: ‘Persistent’ was not declared in this scope
hello_world.cpp:11: error: ‘Context’ was not declared in this scope
hello_world.cpp:11: error: ‘context’ was not declared in this scope
hello_world.cpp:11: error: ‘Context’ is not a class or namespace
hello_world.cpp:15: error: ‘Context’ is not a class or namespace
hello_world.cpp:15: error: expected `;' before ‘context_scope’
hello_world.cpp:18: error: ‘Handle’ was not declared in this scope
hello_world.cpp:18: error: ‘String’ was not declared in this scope
hello_world.cpp:18: error: ‘source’ was not declared in this scope
hello_world.cpp:18: error: ‘String’ is not a class or namespace
hello_world.cpp:21: error: ‘Script’ was not declared in this scope
hello_world.cpp:21: error: ‘script’ was not declared in this scope
hello_world.cpp:21: error: ‘Script’ is not a class or namespace
hello_world.cpp:24: error: ‘Value’ was not declared in this scope
hello_world.cpp:24: error: ‘result’ was not declared in this scope
hello_world.cpp:30: error: ‘String’ is not a class or namespace
hello_world.cpp:30: error: expected `;' before ‘ascii’
hello_world.cpp:31: error: ‘ascii’ was not declared in this scope
hello_world.cpp:31: error: ‘printf’ was not declared in this scope
I don't get why it say V8.h is not declared. I already built it and I'm in its directory and I'm guessing if I get rid of that all the other errors will go away. Any suggestions?
i just believe you in that you are really inside the toplevel source directory (and since i do not have compiled v8 i only believe that libvp8.a is created in that toplevel directory):
% g++ -Iinclude hello_world.cpp -o hello_world libv8.a
it says "v8.h" is not declared because that file is inside the "include" directory and the preprocessor is not able to find it out of thin air.
furthermore: you are compiling a .cpp file with the C compiler instead of the C++ compiler.
you are using the '-o' flag wrong because it defines the name of the linked binary and thus needs a name, you do not want the output binary be named "libvp8.a"