I'm trying to use the Gl3n (https://bitbucket.org/dav1d/gl3n) but
I keep getting error 42 whenever I try this:
alias Vector!(float, 2) vect2;
vect2 position;
position.x = 2.0f; //This is what causes the error
I looked into how the struct was implemented and x is an alias
for a get/set function that interacts with the array that stores
the values for the vector. I've tried something like this:
alias Vector!(float, 2) vect2;
vect2 position;
position = vect2(0.0f, 0.0f);
However, both methods give the same error:
Error 42: Symbol Undefined pure nothrow #property #safe void
gl3n.linalg.Vector!(float,
2).Vector.set_!('x').set_(float) C:\Users\CP\Documents\Visual
Studio 2010\Projects\D\STDS\
Error 42: Symbol Undefined
_D4gl3n6linalg16__T6VectorTfVi2Z6Vector6__initZ
I have the module linalg imported like this at the top:
import Gl3n.linalg; //Gl3n is the folder the source files are in
If I remember correctly, Error 42 is the linker error (optlink).
I don't remember the linker flag, but you need to tell the linker where the library is (gl3n.lib I suppose).
You can use pragma(lib, "gl3n.lib") at the top of your main file assuming gl3n.lib is located in the directory you are compiling from.
Related
I have a third-party library, and I want to use one of the supplied constructors.
ex.h:
/** Construct example from string and a list of symbols. The input grammar is
* similar to the GiNaC output format. All symbols and indices to be used
* in the expression must be specified in a lst in the second argument.
* Undefined symbols and other parser errors will throw an exception. */
ex(const std::string &s, const ex &l);
I tried the following:
symbol x("x");
ex e("x^2",x);
Unfortunately the usage of this constructor is incorrect. I get the following error message:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found
All documentation that is provided is the comment above the declaration. I am a C++ novice, so I have no idea what is wrong.
I tried the suggestion in the first answer like the following:
symbol x("x");
ex expression;
ex e("x^2",expression);
std::cout << diff(e,x) << std::end
This results in the following error message:
libc++abi.dylib: terminating with uncaught exception of type std::invalid_argument: find_or_insert_symbol: symbol "x" not found
(lldb)
Note: I tried using e and expression in diff().
You need to provide an ex reference, not a symbol reference;
Try this:
ex MyEx1; //This will call to the ex default constructor for MyEx1, if it exist.
ex e("x^2",MyEx1); //This will call to the ex constructor that you want to use for e.
The second argument should be a list of symbols occuring in the string (more precisely, a GiNaC::ex handling a GiNaC::lst). This works:
symbol x("x");
ex e("x^2", lst{x});
The idea is that it should work with more than just one symbol:
symbol x("x"), y("y");
ex e("x^2-2*x*y+y^2", lst{x,y});
cout << diff(e, x) << endl; // prints "2*x-2*y" or similar
I'm trying to increment an enum type so I overloaded the operator ++ this way:
enum QuarterType{
FIRST_QUARTER,
SECOND_QUARTER,
THIRD_QUARTER,
FOURTH_QUARTER
};
overloading Operator++:
QuarterType& operator++(QuarterType& quarter){
switch (quarter) {
case FIRST_QUARTER:
return quarter= SECOND_QUARTER;
case SECOND_QUARTER:
return quarter=THIRD_QUARTER;
case THIRD_QUARTER:
return quarter=FOURTH_QUARTER;
case FOURTH_QUARTER:
return quarter=FIRST_QUARTER;
}
}
but when I compile the project I get the error:
duplicate symbol __ZN3mtmppERNS_11QuarterTypeE in:
/Users/../Library/Developer/Xcode/DerivedData/mtm-crtygivbbxwmodgeasndvnjnpczt/Build/Intermediates/mtm.build/Debug/mtm.build/Objects-normal/x86_64/SecurityExample.o
/Users/../Library/Developer/Xcode/DerivedData/mtm-crtygivbbxwmodgeasndvnjnpczt/Build/Intermediates/mtm.build/Debug/mtm.build/Objects-normal/x86_64/Quarters.o
duplicate symbol __ZN3mtmppERNS_11QuarterTypeE in:
/Users/../Library/Developer/Xcode/DerivedData/mtm-crtygivbbxwmodgeasndvnjnpczt/Build/Intermediates/mtm.build/Debug/mtm.build/Objects-normal/x86_64/SecurityExample.o
/Users/../Library/Developer/Xcode/DerivedData/mtm-crtygivbbxwmodgeasndvnjnpczt/Build/Intermediates/mtm.build/Debug/mtm.build/Objects-normal/x86_64/Security.o
ld: 2 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
how can I fix that? and what's the right way or a better way to increment an enum type?
It seems that your operator++ gets exported from multiple compilation units. That could lead to a duplicate symbol error and the cause for that could be definition (not just declaration) of operator++ in a header file. The following options can be used to solve the problem:
Keep operator++ in a header file, but declare it as inline
Leave only the declaration in the header file and move the definition into a .cpp file
Answering the second question (about a better way to increment enum type), I think it is the following in C++11 ( -std=c++11 option to clang compiler):
enum class QuarterType : int {
FIRST_QUARTER = 0,
SECOND_QUARTER = 1,
THIRD_QUARTER = 2,
FOURTH_QUARTER = 3,
TOTAL_QUARTERS = 4
};
inline QuarterType& operator++(QuarterType& quarter) {
int currentQuarter = static_cast<int>(quarter);
int nextQuarter = (currentQuarter+1)
% static_cast<int>(QuarterType::TOTAL_QUARTERS);
quarter = static_cast<QuarterType>(nextQuarter);
return quarter;
}
I've moved a Visual Studio project to a different computer and now GLSL won't compile shaders which previously worked fine. It's getting stuck implicitly converting vec4s to vec3s and it tells me the 'dot' function is undefined, for example.
I'm using the GLSDK and the project builds correctly, and glGetString(GL_SHADING_LANGUAGE_VERSION) tells me 4.40. It's obviously something I don't have installed but used to, but I've searched around and cannot work out what.
Sorry, it sounds like your old drivers were being a bit too permissive. Your new drivers are correct in rejecting the shaders.
vec4 a = vec4(1.0, 2.0, 3.0, 4.0);
vec3 x = vec3(a); // Ok
// vec3 y = a; error
Indeed, if I run the implicit conversion through the reference compiler, I get the following error message:
ERROR: 0:4: '=' : cannot convert from '4-component vector of float' to '3-component vector of float'
ERROR: 1 compilation errors. No code generated.
Try validating your scripts with the reference compiler, it may catch some portability issues like these. Your only real option here is to fix the broken shaders.
What about dot()?
Try this:
#version 330
void main() {
vec4 x = vec4(1.0);
vec3 y = vec3(2.0);
float z = dot(x, y);
}
When I run the validator, I get:
ERROR: 0:5: 'dot' : no matching overloaded function found
ERROR: 1 compilation errors. No code generated.
The error here is that my arguments to dot() are the wrong type. Again, the problem is in my shader.
I have the following enum class:
enum class Message : qint8 {INFO = 0, WARNING = 1, NON_FATAL_ERROR = 2, FATAL_ERROR = 3, DEBUG_INFO = 4};
and when I run the following code with Google Test (checked out from SVN):
EXPECT_NO_THROW(
for(qint32 i = 0; i < 10; ++i)
logger->onIncomingMessage(mapper::Message::INFO, "Testing logging system")
);
The signature of the onIncomingMessage function is:
void onIncomingMessage(const mapper::Message &type, const QString &report);
Visual Studio 2012 shows the following exceptions:
Error 1 error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > testing::FLAGS_gtest_death_test_style" (?FLAGS_gtest_death_test_style#testing##3V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##A) C:\Users\Michele\Projects\occupancymapper\build\Modules\Core\test_logger.obj
3 IntelliSense: enum "mapper::Message" has no member "INFO" c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 21
4 IntelliSense: enum "mapper::Message" has no member "NON_FATAL_ERROR" c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 30
5 IntelliSense: enum "mapper::Message" has no member "DEBUG_INFO" c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 40
6 IntelliSense: enum "mapper::Message" has no member "FATAL_ERROR" c:\Users\Michele\Projects\occupancymapper\Modules\Core\test\test_logger.cpp 50
Error 2 error LNK1120: 1 unresolved externals C:\Users\Michele\Projects\occupancymapper\build\Modules\Core\Debug\logger.exe 1
Without GoogleTests, the code in my class works fine, but when using GoogleTest, it doesn't. Under Linux, it works perfectly.
I've already applied the VARIADIC_MAX value (set to 10), as suggested here in a similar stackoverflow question, but it doesn't work.
What I'm doing wrong?
It looks the error has nothing to do with enum class - these are "IntelliSense" (editor code assistance) errors, not compiler's.
The real problem is that linker cannot find "testing::FLAGS_gtest_death_test_style" symbol. Have you specified .lib file to link with? Make you have built the google test library with the same code generation and debug level settings (this discussion may be helpful).
I've solved the issue.
In my test-case, I've added this:
::testing::FLAGS_gtest_death_test_style = "threadsafe";
right after
::testing::InitGoogleTest(&argc, argv);
because under Linux it was giving me problems.
Removing this line under MSVC, solved the issue and then it compiles.
I have written a library called "myprotocol" in c++ using QT creator as IDE and the normal make command to compile, I have tested the library in a a seperate project as a testbed and the library works perfectly.
Later I try to use the library in another project which uses b2 tool to compile its sources. I am able to link against the myprotocol library but I get strange output errors saying that I have problem in the original "myprotocol" library project, which is not correct.
Here are the errors:
/home/HA/myprotocol/archive.hpp:371:25: error: declaration of ‘operator&’ as non-function
/home/HA/myprotocol/archive.hpp:371:23: error: expected ‘;’ at end of member declaration
/home/HA/myprotocol/archive.hpp:371:41: error: expected ‘)’ before ‘&’ token
This is the the line which contains the error:
iarchive& operator&(CDBRequest& buf);
This is the definition of the CDBRequest:
class CDBRequest
{
public:
CDBRequest() : _cdb_request(0)
{}
CDBRequest(uint16 value)
{
_cdb_request = uint32(value) << 16;
}
CDBRequest& operator=(uint32 cdb_request)
{
_cdb_request = cdb_request;
return *this;
}
void set_value(uint16 value)
{
_cdb_request = uint32(value) << 16;
}
operator uint32&() { return _cdb_request; }
private:
uint32 _cdb_request;
};
This is the command I use to compile my project in b2:
b2 variant=release link=static toolset=gcc include=/home/HA/myprotocol/ linkflags="-L /home/HA/myprotocol/ -lmyprotocol"
Can anyone tell me what might be the problem?
I found the source of the problem:
In the library project I have a header file called "types.hpp", later when I test it in the testbed project, I only have one cpp file.
But eventually when I test it in the root project, the root project has also a header file named "types.hpp" so when I changed the name of the file everything went smoothly.
I think the problem also is because of the #ifdef for both files since they have also the same name.