CURAND undefined reference error - eclipse

I have pretty much the same problem as discussed in this question:
CURAND Library - Compiling Error - Undefined reference to functions
Namely, after having included cuda.h, curand.h and curand_kernel libraries, using
curandGenerator_t gen;
and
curandCreateGenerator(&gen, CURAND_RNG_PSEUDO_DEFAULT);
gives me the following error:
undefined reference to `curandCreateGenerator'
I am aware that this is a duplicate, but I really don't understand what should I do.
I'm using Nsight Eclipse on Ubuntu and I tried adding "-lcurand " to
Project Properties -> Build -> Settings -> Tool Settings -> NVCC Compiler -> Command
and I tried changing it to "nvcc -o RNG7 RNG7.cu -lcurand -Xlinker=-rpath,/usr/local/cuda/lib" as suggested, but nothing seems to work.
I'm a real newbie here, so a little detailed help would be appreciated, along with some reasons behind it, I prefer understanding things to quick fixes!

I got it, it was a very easy fix!
You need to go to:
Project Properties -> Build -> Settings -> Tool Settings -> NVCC Linker -> Libraries
and simply add a new library called "curand".

Related

undefined reference to `memcpy'

I strougle a little bit with my eclipse-arm-project. I get the following errors.
undefined reference to `__aeabi_uldivmod'
undefined reference to `memcpy'
I know the right gcc-lib is missing but I don't know which the right would be and how I could configure eclipse correct to use it.
At the moment I have this relating paths in my project-PATH-variable
C:\...\GNU Tools ARM Embedded\Build Tools\2.8-201611221915\bin (for make)
C:\...\GNU Tools ARM Embedded\5_4_2016q3\bin (for arm-none-eabi-gcc)
The 'Build tools folder' and the 'Toolchain folder' are the same as the second path from the both project-PATH-variable.
I tested a lot of stuff and am now totally confused, may I ask for a little help?
I found the Solution:
In the project settings ('C/C++ Build' -> 'Settings' -> 'Tool-Settings' -> 'Cross ARM C++ Linker' -> 'Gernal') the following flags were active and has to be deactivated.
Do not use default libraries (-nodefaultlibs)
No startup or default libs (-nostdlib)

How to link to pistache in Eclipse C++

I fail to link the pistache library in Eclipse C++ on my Ubuntu machine. I already make this reference:
Properties > C/C++ Build > Settings > Tool Settings
Under GCC C++ Linker > Libraries > Library search path
Under GCC C++ Compiler > Includes > Include paths
Add /usr/local/include/pistache to each
It throws a bunch of errors like this:
.... undefined reference to `Pistache::Ipv4::any()'
Why does this fail? The autocomplete is able to see the reference when I try rewrite the whole line, but it still errors out.
You have to let the linker use shared libraries and pass the -fpic option to the compiler:
a. First step -shared, see this image
b. Last Step Position Independent Code -fPic, see this image
Update
Another way to solve this is:
a. Add support for pthread to the linker
b.Add pistache to libraries in the linker

Threads in Eclipse AND c++11

My goal has been to create multi-threading programs, and I can not even get a simple thread
to execute ON ECLIPSE CDT. my Tools:
ECLIPSE 3.8.1 CDT
Ubuntu 13.10
I have noticed very similar issues regarding mine. I have tried those other solutions but I could not get them to work for me.
When I type the code in Eclipse CDT, Eclipse does not 'resolve' the symbols 'thread', however, It can find the header file 'thread'. 'Mutex' also does not resolve. Furthermore, after building, I run the program, eclipse returns :
"terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted"
Some additional notes:
I can compile and execute the code in the terminal using:
'clang++ c.cpp -pthread -std=c++11'
but...
'g++ c.cpp -pthread -std=c++11' compiles and
produces the same error as quoted above. So it looks like it's a compiler issue. I did
start to write the code in a new project within Eclipse CDT with the clang++ compiler and now that gives the same non-resolved 'thread' and produces the error as quoted above. So now I think I have some wrong settings, paths or flags set in Eclipse.
include <iostream>
include <thread>
using namespace std;
void p1(){
cout<<"process 1 is processing"<<endl;
}
int main() {
thread t1(&p1);
cout<<"Hello from main()"<<endl;
t1.join();
return 0;
}
I have been struggling with the very same issue and I finally resolved it. Here is what I did:
1) Add -std=c++11 for c++ build. To do that right-click your project, select properties and then: C/C++ Build -> Settings -> GCC C++ Compiler -> Miscellaneous(last option)
In other flags append -std=c++11. My Other flags now looks like: -c -fmessage-length=0 -std=c++11 but yours may be a bit different.
2) Add some linker options. In the same view(C/C++ Build -> Settings) as above select the GCC C++ Linker option and from there go to Miscellaneous(second to last option). Add the following Linker flags(the field was empty for me): -Wl,--no-as-needed -pthread. Hit apply.
3) Add a macro. Again from the project properties menu(project->right click->properties). Navigate to C/C++ General -> Paths and symbols -> Symbols. Select GNU C++. Add a symbol with the name __GXX_EXPERIMENTAL_CXX0X__ and no value. Again hit apply.
4) Navigate to C/C++ General -> Preprocessor Include paths.. Select the providers tab. In this tab leave only the following two options checked: CDT GCC Built-in Compiler Settings and CDT Managed Build Setting Entries. Select CDT GCC Built-in Compiler Settings uncheck the checkbox Share setting entries between projects(global provider) and now the text box labeled Command to get compiler specs should be enabled. In this text box append the good old -std=c++11. The text now looks like this for me ${COMMAND} -E -P -v -dD ${INPUTS} -std=c++11. Hit apply one last time.
5) Rebuild the index for the project. To do that right click the project->Index->Rebuild
Following these steps I was able to compile a c++11 multithreaded program, execute it and also Eclipse CDT did not report any errors and was helpful with the autocompletion. Unfortunately this setting has to be done separately for Release and Debug(or at least I have not found a way to share it). Hope this helps.

Eclipse CDT omits leading dash from -D

I am compiling a .c file with a specified _D option MY_OPT. In the properties -> c++ build -> settings -> gcc c compiler -> symbols I creqated an entry and put MY_OPT in as the value.
When I compile I get error 127 saying that DMY_OPT cannot be found. I learned that error 127 means it realy came from bash and, after a bit of thought, I realized that since the dash is not there (as in -DMY_OPT) bash indeed would report that there is no input file named DMY_OPT to be found.
I searched google and stackoverflow and found lots of similar questions, but can't formulate one with narrow enough search terms to fine any remotely related answer, so I hope someone here can help.
NOTE: I removed the SYMBOL and instead put a -DMY_OPT in the miscellaneous field. No change (or I am getting the Eclipse Juno bug about not deleting previous errors.)
I discovered the answer to this question was the test of the overall command line built by Eclipse. Mine read
${COMMAND ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} } ${FLAGS}
^ ^
} accidentally moved to here ---------------------->|
I had meant to move ${FLAGS} to the end of the command line but also managed to move the right side } form ${COMMAND}..
NOTE: This was done to get the compile command line to look like the linker command line where one should move ${FLAGS} to the end of the line thus putting the list of ".o's" and the "-o xxx" before the "_l's: and "-L's" as is required by some releases of gcc/g++.

Eclipse giving me Invalid arguments ' Candidates are: void * memset(void *, int, ?) ' though I know the args are good

I am getting an invalid arguments error in eclipse, though I am confident my arguments are good. The suggested arguments contains a '?' which I think may indicate the problem, though I do not know how to fix it.
I have done my best to copy the example I saw here:
http://www.cplusplus.com/reference/clibrary/cstring/memset/
In order to be certain that I am getting the args right.
#include <stdio.h>
#include <string.h>
void foo()
{
char str[] = "why oh why does my IDE give me errors when I know my args are good?";
memset(str, '-', 4);
puts(str);
}
Eclipse gives me the following error on the memset line:
Invalid arguments ' Candidates are: void * memset(void *, int, ?) '
What could be causing this? And what is up with that '?' as the 3rd arg?
Thanks in advance!
PS: Just noticed I am getting similar errors when I try to use operations like malloc, calloc, etc.
In Eclipse:
right click the project
click properties
Expand "C/C++ general" the item in the left hand tree view by clicking the arrow, (just clicking the item itself does not expand the suboptions)
From the suboptions select "Preprocessor Include Paths, Macros etc."
Click the "Providers" tab
Check the box next to "CDT GCC Built-in Compiler Settings [ Shared ]".
Edit:
The reason this works is that there are a bunch of default includes and defines that the compiler silently adds behind the scene when you compile. These instructions get eclipse to grab these otherwise silent preprocessor directives so that it's own indexer is using the same settings
The following method resolves the same problem that I was having. (on eclipse 4.2)
Clean your project (Project -> Clean)
Reindex files (Project -> C/C++ Index -> Rebuild)
Rebuild your project (Project -> Build All)
I think it is something to do with your Eclipse setup, somehow.
Taken standalone, that fragment compiles under GCC (G++) 4.7.1 on Mac OS X 10.7.5 with the command line:
g++ -O3 -g -Wall -Wextra -c ms.cpp
The only surprising thing about the third argument to memset() is that it is of type size_t, but the headers are supposed to declare that, so it should not be an issue.
If you're using malloc() et al, you will be including <stdlib.h>, of course. There is also room to argue that you should be using <cstdio>, <cstring> and <cstdlib>, but that shouldn't stop the code you presented from compiling without error.
If you're working with Visual Studio, size_t is defined as
typedef unsigned __int64 size_t;
In previous versions of the Eclipse CDT, __int64 was not defined. You can fix that issue by adding into C/C++ General -> Paths and Symbols -> Symbols
Symbol: __int64
Value: long long
Or you can upgrade your Eclipse CDT version
I've been using a 3rd party C++ library for BeagleBone development and I tried every possible way to include it (as preprocessor includes, source folder, assember includes, library includes, C++ compiler includes, C compiler includes etc). Refreshen, reindex, clean and built for every change I attempted. I even deleted the project and copied only the .cpp and .h files over to a new project.
I finally found the problem in my setup and rectified it as follows.
Right-click the project > Properties > C/C++ Build > Tool-chain editor > Current Builder:> Select CDT Internal Builder
I'm using g++, for your information.
I had a similar issue with the Eclipse CDT. But in my case the thing was that I had put the using namespace std; statement in a several headers. And in some combination of conditions, when I included all of this headers the Eclipse had such the behavior.
I had a similar issue when compiling someone's code, and the problem was the code style. They defined some methods in this way:
// ... Inside a class
static void
sleep( u32 ms );
I guess this is GNU style. Just changing the declaration to
static void sleep( u32 ms );
removed the issue.