I looked at an example for solving a system of linear equations using GSL and it contained this line:
gsl_matrix_view m = gsl_matrix_view_array (a_data, 4, 4);
I looked in the GSL source code and found the declaration for gsl_matrix_view_array inside the file gsl_matrix_double.h. However I couldn't find the definition anywhere.
Where could the definition of gsl_matrix_view_array be?
I found out from elsewhere that gsl_matrix_view_array is defined in gsl/matrix/view_source.c using macros.
Related
In the llvm project tutorials, they usually have a Skeleton file in which an external function is called, while it's body is implemented in a c file whose .bc will be linked to have the resulting bitcode to find the external function.
However, looking at the implemented LLVM projects in github, I do not see them using any c file and linking it to the resulting bitcode.
My question is how I can define a function and create a call to the function. Is defining intrinsic functions the only way?
When defining a function in cpp, and having a createCall to the function, it does not find definition of the function defined in cpp when running the bitcode/or the binary.
I'm not sure if I understand your question right, but will try to answer.
When you do Function* myF = module->getOrInsertFunction("myF", ...); you just create a declaration for it. Much like void myF(...); in C/C++ header file.
To turn myF into a definition, you create BasicBlocks, populate them with Instructions and then insert these BasicBlocks into myF. This will make myF defined in your module and you won't see "definition not found" error anymore.
I am trying to implement rotation in and the MSDN document has suggested everywhere to use Vector3 structure to achieve this. However I get an error for both Vector3 and Quaternion saying identifier not defined
I understand this is because of not including the appropriate header file or not linking the proper library. I searched online but could not find which exact file to link and include.
So, I'm playing with GNUTLS, and it has this enum:
typedef enum {
GNUTLS_PK_UNKNOWN = 0,
GNUTLS_PK_RSA = 1,
GNUTLS_PK_DSA = 2,
GNUTLS_PK_DH = 3,
GNUTLS_PK_EC = 4
} gnutls_pk_algorithm_t;
sitting in it's main header file(gnutls.h, version 3.3.17). I reference it here:
unsigned int bits = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_LEGACY);
(right out of the example). I do have the #include <gnutls/gnutls.h>, and that all seems to reference fine(other enums are fine, except for GNUTLS_X509_FMT_PEM). I read something about the compiler not seeing gnutls.h, and it is in /usr/local/include and not /usr/include, however I do have that in the Includes side thing in Eclipse. If it is a compiler-not-finding-it, why is it finding some values, and how do I make it find it? If not, what is the issue?
how to find? add -I/usr/local/include to your gcc command line, or CFLAGS in the makefile, or look here for how to add it in eclipse
If the compiler is finding some values while not finding the include, maybe they defined elsewhere. try to redefine them, and look in the error where the other definition is.
to redefine you can declare as different type, (like: typedef int whatever;, to see if and where whatever declared) since if it is the same typedef it may considered as a forward deceleration.
This is my first time tackling a CUDA project that's slightly more complex than the simple write-single-source-file-and-compile routine. As expected, I'm facing some issues with C headers, namely duplicated symbols.
According to the linker, conflicts arise over the inclusion of the following header file in multiple .cu files:
env_vars.h
#ifndef ENV_VARS_H_
#define ENV_VARS_H_
/*** GLOBAL VARIABLES ***/
unsigned int h_n_osc;
__device__ unsigned int d_n_osc;
/*** CONSTANTS ***/
const double OMEGA_0 = 6.447421494058077e+09;
/* other constants defined in the middle */
#endif
multigpu.cu
#include "env_vars.h"
/* assigns h_n_osc */
adm_matrix.cu
#include "env_vars.h"
/* uses h_n_osc */
Building the project in Nsight Eclipse Edition results in the linker complaining about the h_n_osc variable being defined twice:
duplicate symbol _h_n_osc in:
./adm_matrix.o
./multigpu.o
ld: 1 duplicate symbol for architecture x86_64
Searching through the Internet, I've realized that moving the declaration of the h_n_osc variable to multigpu.cu and re-declaring it as an extern variable in adm_matrix.cu (and wherever I might need it later) solves the problem, which in fact it does.
Problem solved, but I'd like to take a deeper look into this:
Why doesn't the linker complain about the d_n_osc variable as well? And why are the constants (such as OMEGA_0) equally not a problem?
Does this mean that it is not possible to place global variables in header files?
What puzzles me most is that a number of sources over the Internet state that duplicated symbol errors should happen only when the header file contains a definition of the variable, while its simple declaration shouldn't constitute a problem. The reason I have a hard time believing this is that I'm facing the issue even though my header only contains a declaration! Am I missing something?
Thanks in advance for your patience, folks!
Header files should normally contain only declarative code. h_n_osc should be declared here, not defined.
extern unsigned int h_n_osc;
In at least one of your modules, or a new one of its own you will need a definition; for example:
env_vars.cu
#include "env_vars.h"
unsigned int h_n_osc;
Then link that. Alternatively you could of course place the definition in one of the existing modules multigpu.cu or adm_matrix.cu.
I am not sure of the semantics of the The CUDA __device__ extension, while it may link, it is not necessarily correct; you may end up with each module referencing a separate copy of the device variable; it may be necessary to qualify that with extern as well. This question appears to deal with that issue.
vector is included in only one source file. The only stl include in the header files is string. Yet I cannot get rid of multiple definition errors (example below). Any ideas?
./plugin_dfb.o:mipsel-linux-uclibc/include/c++/4.2.0/bits/stl_bvector.h:182: multiple definition of `std::operator-(std::_Bit_iterator_base const&, std::_Bit_iterator_base const&)'
./painter.o:mipsel-linux-uclibc/include/c++/4.2.0/bits/stl_bvector.h:182: first defined here
This std::operator- is an inline function with external linkage. It appears the linker doesn't support multiple definitions of such inline functions. But the "one definition rule" of C++ (ODR) clearly allows this. Typically such symbols get "weak linkage" (GNU terminology) but I think both, the object file format and the linker, need to support this.
I would try to ask a question in a group / mailing list dedicated to your platform. Something along the lines of "Does platform X support C++ with respect to linking and the C++-related one-definition rule for inline functions and templates?".
You may also want to check the GCC documentation. It's possible that they provide a command line switch as a work-around. If you don't already use g++ as front-end to the linker, you should try it. Maybe that helps, too.
have you tried using #pragma once?
I think you have included the vector in only one header file but that header file is not having the #define block, this is resulting the redefinition of the vector header file included in it.
Please enclose your include file in the template given below and try.
#if !defined(HEADER_FILE)
#define HEADER_FILE
// Your code
#endif
As the problem appears during linking it looks to be related to template instantiation. Given instantiation implementation specifics the template functions/definitions should be put in the common include files to assure they are visible everywhere and do not duplicate header includes what may be the case here.
From what you posted problem concerns the operator - that may be used by std::distance() that may be called from find() type functions. So look if you have such functions defined or called as they may work with vectors and strings and make sure they are in shared header files.