file1.cpp
gcc version 4.9.2
.
.
#ifdef _WIN32
__declspec(dllexport)std::vector<int> g_vDelay;
#else
__attribute__((visibility("default")))
extern std::vector<int> g_vDelay;
#endif
.
.
void SetDelayTimes(std::vector<int>& vDel)
{
g_vDelay.swap(vDel);
}
.
.
file1.cpp:386:2: error: ‘g_vDelay’ was not declared in this scope
g_vDelay.swap(vDel);
^
Related
My .h file has this code for the __cplusplus version in use:
#define CPP14_SUPPORTED (__cplusplus >= 201402L)
#if CPP14_SUPPORTED
#define IS_CPP14_SUPPORTED 1 // BUT THIS IS GREYED OUT in the .h file!
#endif
The main issue is that all my .h files do not see this definition as well.
When I use the definition IS_CPP14_SUPPORTED in my .cpp file it shows that it is true and not greyed out.
I am using keil uvision5 IDE
Try this
#define CPP14_SUPPORTED __cplusplus >= 201402L
#if CPP14_SUPPORTED
#warning "cpp14 supported"
#else
#warning "Cpp14 not supported"
#endif
With -std=c++14 it prints
<source>:3:5: warning: #warning "cpp14 supported" [-Wcpp]
3 | #warning "cpp14 supported"
| ^~~~~~~
With -std=c++11 it prints
<source>:5:5: warning: #warning "Cpp14 not supported" [-Wcpp]
5 | #warning "Cpp14 not supported"
| ^~~~~~~
The below c++ code gives me error use of undeclared identifier 'temp'
/home/test/include/memory.h
#ifndef MEMORY_H
#define MEMORY_H
#if __ENABLE_MEMORY
__device__ int temp = 50;
extern "C" inline __device__ void* memory(){
...
temp = temp + 100;
...
}
#endif
#endif
/home/test/include/internal_memory.h
#ifndef INTERNAL_MEMORY_H
#define INTERNAL_MEMORY_H
#ifndef __ENABLE_MEMORY
#define __ENABLE_MEMORY 1
#endif
#if __ENABLE_MEMORY
extern "C" __device__ void* memory();
static inline __device__ void* call_memory(){ return memory();}
#endif
#include <memory.h>
#endif
/home/test/main.cpp
#include "internal_memory.h"
..
.
.
void show(){
std::cout << "temp is: " << temp << std::endl;
}
.
.
.
I m compiling the code with clang++ version 11.0.0.
clang --version looks as follows:
clang version 11.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/rocm/llvm/bin
Im compiling the code as below.
/opt/rocm/llvm/bin/clang++ -DDEBUG -D__x86_64__ -I/home/test/include -I/home/test -g -fPIC -std=c++14 -o main.o -c main.cpp
what am i missing here.
Function memory has the __device__ qualifier (I suppose you are compiling a CUDA program).
memory refers to temp, which is a global variable in host memory. You probably want __device__ int temp = 50;
To query temp, you would need to copy its value back to the host. Along the lines of
int host;
cudaMemcpy(&host, &temp, sizeof(int), cudaMemcpyDeviceToHost);
Given the following code:
#if MACRO_WITHOUT_A_VALUE
int var;
#endif
int main(){}
When compiled with, g++ -std=c++1z -Wundef -o main main.cpp,
it produces the following warning:
main.cpp:1:5: warning: "MACRO_WITHOUT_A_VALUE" is not defined [-Wundef]
#if MACRO_WITHOUT_A_VALUE
^
I'd like to keep the warning flag enabled, but suppress this particular instance.
I apply the following:
#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wundef"
#pragma GCC diagnostic push
#endif
#if MACRO_WITHOUT_A_VALUE
int var;
#endif
#ifdef __GNUC__
#pragma GCC diagnostic pop
#endif
int main(){}
This only solves the problem in clang++.
The command clang++ -std=c++1z -Wundef -o main main.cpp builds without warnings.
The command g++ -std=c++1z -Wundef -o main main.cpp builds with the same [-Wundef] warning as before.
How can I suppress -Wundef warnings in g++?
g++ (Ubuntu 5.1.0-0ubuntu11~14.04.1) 5.1.0
clang version 3.8.0
What I've done before when third party headers were inducing warnings was to wrap them in my own private header that uses #pragma GCC system_header to just silence all the warnings from that header. I use my own wrapper to keep the includes neat and allow for an additional customization point in the future if needed.
This isn't disabling the warning, but fixing the preprocessor code to avoid it.
The below tests are based on a similar issue here, using clang -Weverything...
#define ZERO 0
#define ONE 1
#define EMPTY
// warning: 'NOTDEFINED' is not defined, evaluates to 0 [-Wundef]
#if NOTDEFINED
#warning NOTDEFINED
#endif
// false
#if ZERO
#warning ZERO
#endif
// true
#if ONE
#warning ONE
#endif
// error: expected value in expression
#if EMPTY
#warning EMPTY
#endif
// false
#if defined(NOTDEFINED) && NOTDEFINED
#warning NOTDEFINED
#endif
// false
#if defined(ZERO) && ZERO
#warning ZERO
#endif
// true
#if defined(ONE) && ONE
#warning ONE
#endif
// error: expected value in expression
#if defined(EMPTY) && EMPTY
#warning EMPTY
#endif
The one liner #if defined(SOME_MACRO) && SOME_MACRO can avoid this warning. To explicitly handle the case...
#if defined(DEBUG_PRINT)
#if DEBUG_PRINT
... true
#else
... false
#endif
#else
#error DEBUG_PRINT must be defined
#endif
To handle EMPTY see this: How to test if preprocessor symbol is #define'd but has no value?
I'm trying to compile a very simple program using Boost Test Unit
#define BOOST_TEST_MODULE My Test
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(first_test) { int i = 1; BOOST_CHECK(i == 1); }
If I compile this small program with no parameters,
g++ test1.cpp
there's no problem. But, if I try to use C++11 standard,
g++ test1.cpp -std=c++11
I get some errors:
In file included from /usr/include/boost/test/included/unit_test.hpp:19:0,
from test1.cpp:2: /usr/include/boost/test/impl/debug.ipp: En la función ‘const char* boost::debug::{anónimo}::prepare_gdb_cmnd_file(const boost::debug::dbg_startup_info&)’: /usr/include/boost/test/impl/debug.ipp:426:23: error: ‘::mkstemp’ no se ha declarado
fd_holder cmd_fd( ::mkstemp( cmd_file_name ) );
^ In file included from /usr/include/boost/test/included/unit_test.hpp:19:0,
from test1.cpp:2: /usr/include/boost/test/impl/debug.ipp: En la función ‘bool boost::debug::attach_debugger(bool)’: /usr/include/boost/test/impl/debug.ipp:863:34: error: ‘::mkstemp’ no se ha declarado
fd_holder init_done_lock_fd( ::mkstemp( init_done_lock_fn ) );
^ In file included from /usr/include/boost/test/utils/runtime/cla/dual_name_parameter.hpp:19:0,
from /usr/include/boost/test/impl/unit_test_parameters.ipp:31,
from /usr/include/boost/test/included/unit_test.hpp:33,
from test1.cpp:2: /usr/include/boost/test/utils/runtime/config.hpp: En la función ‘void boost::runtime::putenv_impl(boost::runtime::cstring, boost::runtime::cstring)’: /usr/include/boost/test/utils/runtime/config.hpp:95:51: error: ‘putenv’ no se declaró en este ámbito
putenv( const_cast<char*>( fs.str().c_str() ) );
(The compiler is in spanish)
I'm using:
Cygwin 64 bits
Cygwin's Boost 1.59
Cygwin's G++ 4.9.3
Any help will be welcome. Thanks.
José.-
Looks like it is a Cygwin thing. I could not reproduce it on OpenSUSE 13.2 i586 with Boost 1.54, but got the same result as yours on Cygwin Win32 with Boost 1.57. And, as Bo Persson suggested, also tried std=gnu+11.
As the compiler sayd “not declared” — even if you explicitly include <stdlib.h> which declares both mkstemp and putenv, — it seemed doubtful to me that it was all about C++ language extensions, but rather more like header file issue. Indeed, in Linux we have:
#if defined __USE_MISC || defined __USE_XOPEN_EXTENDED \
|| defined __USE_XOPEN2K8
# ifndef __USE_FILE_OFFSET64
extern int mkstemp (char *__template) __nonnull ((1)) __wur;
# else
# ifdef __REDIRECT
extern int __REDIRECT (mkstemp, (char *__template), mkstemp64)
__nonnull ((1)) __wur;
# else
# define mkstemp mkstemp64
# endif
# endif
# ifdef __USE_LARGEFILE64
extern int mkstemp64 (char *__template) __nonnull ((1)) __wur;
# endif
#endif
But in Cygwin:
#ifndef __STRICT_ANSI__
#ifndef _REENT_ONLY
int _EXFUN(mkstemp,(char *));
#endif
int _EXFUN(_mkstemp_r, (struct _reent *, char *));
#endif
Then I added a couple of #undefs to your program:
#undef __STRICT_ANSI__
#undef _REENT_ONLY
#define BOOST_TEST_MODULE My Test
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(first_test) { int i = 1; BOOST_CHECK(i == 1); }
And could compile it fine with std=c++11. I have no idea how incorrect and stupid this may be, but at least it produced very similar exe file that only differs by 20 bytes (aside from fingerprint).
#include <iostream>
#include <string.h>
char* basename(const char* filname);
int main()
{
return 0;
}
char *basename(const char* filename)
{
char* base = (char *)filename;
return base ;
}
compiling on g++ 4.1.2 20070115 (SUSE 10): No issue
compiling on g++ 4.3.4 (SUSE 11) gives following error
fileName : 9 :error:declaration of char* basename(const char*) throws different exception
fileName:3:error: from previous declaration char* basename(const char*) throw () .
Kindly tell me why this is happening , Is there is any Interface changed in g++ between these two release (if I remove inclusion of string.h then compilation success on both version of g++ ,Is any Interface change in string.h).
looks like basename already defined in string.h
# ifndef basename
/* Return the file name within directory of FILENAME. We don't
declare the function if the `basename' macro is available (defined
in <libgen.h>) which makes the XPG version of this function
available. */
# ifdef __CORRECT_ISO_CPP_STRING_H_PROTO
extern "C++" char *basename (char *__filename)
__THROW __asm ("basename") __nonnull ((1));
extern "C++" __const char *basename (__const char *__filename)
__THROW __asm ("basename") __nonnull ((1));
# else
extern char *basename (__const char *__filename) __THROW __nonnull ((1));
# endif
# endif
It seems the name basename already exists in string.h:
http://ideone.com/Q9xSw - gives error (as it is exactly your code).
http://ideone.com/s0HIX compiles fine if you comment #include <string.h>