I'm trying to run some tests on vsoc_beta using arm-elf-gcc and arm-rtems-gcc. However, both compilers gave me the same error:
/home/student/vsoc-beta/apps/libgomp/root.o: In function `main':
/home/student/vsoc-beta/apps/libgomp/libgomp.c:24: multiple definition of `main'
app_obj.o:/home/student/vsoc-beta/apps/rotate/rot.c:103: first defined here
/home/student/vsoc-beta/apps/libgomp/root.o: In function `main':
root.c:(.text+0x219c): undefined reference to `_app_main'
root.c:(.text+0x2298): undefined reference to `_app_main'
make: *** [o-optimize/app.exe] Error 1
These tests are using libgomp and in libgomp.c there's a line:
extern int _app_main(int argc, char **argv, char **envp);
and the main is defined as:
int main(int argc, char **argv, char **envp)
In the test files, there is another main function:
int main(int argc, char **argv)
What could be the problem?
As the first error is a "Multiple definition of main" you must decide first which of the 2 main function you have is the application entry point.
An application as only one entry point or main function.
Related
I have a simple program to test basename() method:
#include <stdio.h>
#include <string.h>
//#include <libgen.h>
int main (int argc , char **argv)
{
char *a = strdup("test();");
printf("%s", basename(a));
return 0;
}
clang complains but it compiles anyway.
test.c:7:18: warning: implicit declaration of function 'basename' is invalid in C99 [-Wimplicit-function-declaration]
printf("%p", basename(a));
^
test.c:7:18: warning: format specifies type 'void *' but the argument has type 'int' [-Wformat]
printf("%p", basename(a));
And it results in segfault. But if I added libgen.h header, it works normally.
I've checked the binary with otool, it linked against the same dylib, nothing else. Why does the first one crash?
I've checked the answer here already, it uses a static buffer but I use the result from strdup(), so it's a different question.
The program does nothing except farewell to the world:
/* Ubuntu 18.04 with GCC 10.1.0 and libstdc++-10-dev */
#include <memory_resource>
#include <concepts>
#include <ranges>
#include <string_view>
/* declare global memory resource */
std::pmr::synchronized_pool_resource pool;
int main(int argv, char * argc[]){
std::puts("Goodbye World!");
}
It compiles fine, but terminates with SEGV on
/usr/include/c++/10/memory_resource
line 445, in constructor of SPR:
synchronized_pool_resource()
: synchronized_pool_resource(pool_options(), get_default_resource())
[Unknown/Just-In-Time compiled code] (Unknown Source:0)
libstdc++.so.6!std::pmr::synchronized_pool_resource::synchronized_pool_resource(std::pmr::pool_options const&, std::pmr::memory_resource*) (Unknown Source:0)
std::pmr::synchronized_pool_resource::synchronized_pool_resource(std::pmr::synchronized_pool_resource * const this) (/usr/include/c++/10/memory_resource:445)
__static_initialization_and_destruction_0(int __initialize_p, int __priority) (/data/solution/projects/test/source/main.cpp:10)
_GLOBAL__sub_I__Z4testRNSt3pmr26synchronized_pool_resourceE() (/data/solution/projects/test/source/main.cpp:16)
__libc_csu_init (Unknown Source:0)
libc.so.6!__libc_start_main(int ()(int, char **, char **) main, int argc, char ** argv, int ()(int, char **, char **) init, void ()(void) fini, void ()(void) rtld_fini, void * stack_end) (/build/glibc-OTsEL5/glibc-2.27/csu/libc-start.c:266)
_start (Unknown Source:0)
The chain of calls on stack explains me that the program might have been linked to libstdc++.so.6. Is this a possible reason and if so, what shall I do?
I was using
GNU gdb (Ubuntu 8.2-0ubuntu1~18.04) 8.2
for debugging. Would it be because GDB is not ready for this?
BTW: I really wasn't capable of using this editor to past images. It just doesn't show up.
You need to add -pthread to your g++ linking call. I can't fault you if you think there should be a comprehensible error message…
This question is a followup on a similar question with java code - how-to-report-grammar-ambiguity-in-antlr4. I am trying to port that code to c++, but I am facing some compilation errors with using the antlr templates.
The main program in c++ is the following:
// TestA_Main.cpp
using namespace std;
using namespace antlr4;
using namespace atn;
int main(int argc, char **argv)
{
string filename = argv[0];
ifstream stream;
stream.open(filename);
ANTLRInputStream input(stream);
AmbigLexer lexer(&input);
CommonTokenStream tokens(&lexer);
AmbigParser parser(&tokens);
parser.addErrorListener(new DiagnosticErrorListener());
// the following line has an error on the call to getInterpreter
parser.getInterpreter().setPredictionMode(PredictionMode::LL_EXACT_AMBIG_DETECTION);
parser.stat();
}
I ran the following commands on it:
java org.antlr.v4.Tool -Dlanguage=Cpp Ambig.g4
g++ -std=gnu++0x -I. -I/antlr4_cpp/runtime/include -I/antlr4_cpp/runtime/include/atn TestA_Main.cpp
And I am getting the following compilation errors, on the call to getInterpreter:
TestA_Main.cpp: In function ‘int main(int, char**)’:
TestA_Main.cpp:27:27: error: no matching function for call to ‘AmbigParser::getInterpreter()’
parser.getInterpreter().setPredictionMode(PredictionMode::LL_EXACT_AMBIG_DETECTION);
^
In file included from /softwares/antlr4/antlr4_cpp/runtime/include/Lexer.h:8:0,
from /softwares/antlr4/antlr4_cpp/runtime/include/antlr4-runtime.h:32,
from TestA_Main.cpp:4:
/softwares/antlr4/antlr4_cpp/runtime/include/Recognizer.h:73:8: note: candidate: template<class T> T* antlr4::Recognizer::getInterpreter() const
T* getInterpreter() const {
^
/softwares/antlr4/antlr4_cpp/runtime/include/Recognizer.h:73:8: note: template argument deduction/substitution failed:
TestA_Main.cpp:27:27: note: couldn't deduce template parameter ‘T’
parser.getInterpreter().setPredictionMode(PredictionMode::LL_EXACT_AMBIG_DETECTION);
Can you please tell me how to fix the above code? I am using antlr-4.6
It's a template function and you have to specify the template parameter explicitly:
parser.getInterpreter<ParserATNSimulator>()->setPredictionMode(PredictionMode::SLL);
I'm trying to use thrust::transform to operate on vectors of type thrust:complex<float> without success. The following example blows up during compilation with several pages of errors.
#include <cuda.h>
#include <cuda_runtime.h>
#include <cufft.h>
#include <thrust/device_vector.h>
#include <thrust/host_vector.h>
#include <thrust/transform.h>
#include <thrust/complex.h>
int main(int argc, char *argv[]) {
thrust::device_vector< thrust::complex<float> > d_vec1(4);
thrust::device_vector<float> d_vec2(4);
thrust::fill(d_vec1.begin(), d_vec1.end(), thrust::complex<float>(1,1));
thrust::transform(d_vec1.begin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
}
I'm using CUDA 8.0 on Ubuntu Xenial and compiling with clang 3.8.0-2ubuntu4 using nvcc --std=c++11 main.cpp -o main.
Main errors appear to be:
main.cpp: In function ‘int main(int, char**)’:
main.cpp:17:105: error: no matching function for call to ‘abs()’
gin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
and
/usr/local/cuda-8.0/bin/../targets/x86_64-linux/include/thrust/detail/complex/arithmetic.h:143:20: note: template argument deduction/substitution failed:
main.cpp:17:105: note: candidate expects 1 argument, 0 provided
gin(), d_vec1.end(), d_vec2.begin(), thrust::abs< thrust::complex<float> >() );
^
No problem working on real floats, but no such with complex ones. I'm thinking there's a type error that I'm missing, but I'm very much still on the steep part of the learning curve with Thrust & templates.
The error message is quite descriptive:
thrust::abs<thrust::complex<...>> is a function which expects exactly one parameter, see thrust/detail/complex/arithmetic.h#L143:
template <typename ValueType>
__host__ __device__
inline ValueType abs(const complex<ValueType>& z){
return hypot(z.real(),z.imag());
}
For your use case, you need to wrap that function by a functor:
struct complex_abs_functor
{
template <typename ValueType>
__host__ __device__
ValueType operator()(const thrust::complex<ValueType>& z)
{
return thrust::abs(z);
}
};
Finally, employ that functor here:
thrust::transform(d_vec1.begin(),
d_vec1.end(),
d_vec2.begin(),
complex_abs_functor());
during compiling older C++ code on Ubuntu 11.10 with mpic++ (Open MPI C++ wrapper compiler) I got this warning connected with int main(int argc, char **argv){...}:
main(int, char**) : warning: deprecated conversion from string constant to ‘char*’
I tried to edit the code to int main(int argc, const char *argv[]){...} but it did not help (contrary to e.g. this issue).
What did I wrong? How can I fix it?