I've been trying for about 6 hours... to make use of the SDL2_gfx library in my project on Xcode 8.0.
I'll tell you right now, I'm a complete newbie to all of this, terminal commands, including libraries and stuff.
I've managed to use SDL2 fine, for there is a .framework, but the SDL2_gfx only comes as a folder with a .a, .dylib, .h and a mysterious .json.
I've installed it through homebrew whithout problems, but now, how do I make a project using it ??
In the Build Phases and Build Settings :
I've tried linking .a and .dylib via "Link Binary With Libraries",
I've added the headers paths in "Headers Search Paths" in "Search Paths",
I've tried adding the .h to my project directly,
and I have absolutely no idea of what to put in "Other Linker Flags" as it what suggested in many answers.
I keep getting the very simple error "no matching function for call ..." whenever I try using a function. But I'm doing it the same way as in some examples on the internet, and I checked in the .h, the functions do exist...
Please help T_T
EDIT :
I've managed to find functions that are apparently recognized :
Sint16 circleR = 100;
Sint16 circleX = 300;
Sint16 circleY = 300;
int result = filledCircleColor(gRenderer, circleX, circleY, circleR, 0xFF0000FF);
std::cout << "draw circle result " << result << std::endl;
int a = pixelRGBA(gRenderer, circleR, circleR, 0xFF, 0x00, 0x00, 0xFF);
std::cout << "draw pixel result " << a << std::end;
But come out with result -1, which means it didn't work.
Still can't figure it out...
I suppose I'm not using them correctly, but I can't find any different example on the internet.
i think i see your problem : you are calling with as 1st parameter a RENDERER. The function header expects a SURFACE :
http://www.ferzkopp.net/Software/SDL_gfx-2.0/Docs/html/_s_d_l__gfx_primitives_8h.html#a4f7b717b958ef39bfc8c958476dd0de1
clearly defines the function as :
SDL_GFXPRIMITIVES_SCOPE int filledCircleColor ( SDL_Surface * dst,
Sint16 x,
Sint16 y,
Sint16 rad,
Uint32 color
)
Related
I have an application that uses mongoose as a library. After updating Xcode to 13.1 (macOS Monterey) I am getting a compile error that I can't figure out how to fix:
type 'struct ah' has incompatible definitions in different translation units
This is in a block of code within mongoose where a struct is being defined and used:
// Parsed Authorization header
struct ah {
char *user, *uri, *cnonce, *response, *qop, *nc, *nonce;
};
// Return 1 on success. Always initializes the ah structure.
static int parse_auth_header(struct mg_connection *conn, char *buf,
size_t buf_size, struct ah *ah) {
char *name, *value, *s;
const char *auth_header;
(void) memset(ah, 0, sizeof(*ah));
if ((auth_header = mg_get_header(conn, "Authorization")) == NULL ||
mg_strncasecmp(auth_header, "Digest ", 7) != 0) {
return 0;
}
I would really rather not modify the code since it's a 3rd party library that may receive updates. But at the same time I have to be able to build my app.
Is there an Xcode setting that I'm not seeing to get around this? I'm not sure what the error even means.
For anyone having problems with this in 2022 and who don't want or can't rename their structs:
I have found this post on a Chinese blog: https://www.cnblogs.com/dzqdzq/p/9977638.html
Basically, the easy fix seems to be to disable the "Enable Modules (C and Objective-C)" build setting. It seems disabling this option makes the XCode Clang compiler work in a way that is more similar to GCC.
I checked this in both VS and CodeBlocks. CodeBlocks showed me the same address over and over but in VS the address changed every time I ran my program.
int main()
{
int x, * p;
x = 5;
p = &x;
cout<<"the address of "<< *p <<" is : " << p << endl;
}
Wild guess: one is enabling address layout randomization and the other is not. Check the build options in both for an option that enables and disables it. For Microsoft's compiler this appears to be /DYNAMICBASE Assuming it was enabled and you disable it, you may see consistent results.
I'm using eigen to do some matrix operation, but the compile time for the src files using eigen is very slow, by slow I mean it take about 40s when the file is only 300 lines. I only use Matrix smaller than Matrix4f and not even use dynamic size matrix, for only some matrix multiplication and matrix decomposition(SVD and FullPivLU).
In my other project where a cpp file is 1000 lines, it take minutes to compile, and the output .so file is really big, about 100M. I have to open the -bigobj choice.
This happens both in debug(where I set the opimization to -O0) and release(-O3) mode. I've tried add #define NDEBUG and EIGEN_NO_DEBUG in the header, not help.
I write this piece of very small code test.cpp below:
#include </home/user/mywork/software/eigen-3.3.9/Eigen/Dense>
#include "iostream"
using namespace std;
using namespace Eigen;
void test()
{
Matrix3f A;
A << 1,2,3,4,2,8,5,4,9;
BDCSVD<Matrix3f> svd(A, ComputeFullU | ComputeFullV);
Matrix3f U = svd.matrixU();
Matrix3f V = svd.matrixV();
cout << "------Eigen------" << endl;
cout << "A" << A << endl;
cout << "U" << U << endl;
cout << "V" << V << endl;
}
int main()
{
test();
return 0;
}
compile command
g++ test.cpp -o test_eigen
it take 20s to compile, and the output 'test_eigen' is 5.6M!!!
my os is ubuntu 16.04 and I use cmake, in the CMakelist, only thing related to eigen is include its directory. eigen version is 3.3.9.
does anyone have any clue? Thanks a lot.
Eigen consists of 7.8MB of pure header files. So any .cpp including it will have a hard life compiling (uses giga-bytes of memory and extremely slow). In addition, due to extensive use of templates and inline functions, the DEBUG version will be so slow and unusable for debug purpose. (For example, google's Cartographer will warn about debug version) and I also made some tests.
So I think Eigen should be used as follow:
Encapsulate Eigen. Create simple interface according to your own needs. (For example, create matrix_4x4.h, vector4.h, standard_deviation_calculaor.h, etc.) Include Eigen only in .cpp files. The exposed .h files will be so simple and will not propagate to slow down compiling of other files.
Proper Modularization. Precompile the library into static/shared libraries. And use the simple headers in other parts of your program.
Restrain Use eigen only in performance-critical parts of my program. For example, the following function will not use eigen and should be inlined(exposed in header):
// vector3.h
inline Vector3 operator + (const Vector3& l, const Vector3& r) {
return Vector3(l.x + r.x, l.y + r.y, l.z + r.z);
}
But Matrix4x4::multiplyInplace(const Matrix4x4& r) will be
implemented in .cpp and use Eigen.
I want to use boost::hash_combine in my project. However, I was unable to find the boost library that contains this function (the library libboost_functional does not exist). I am running Arch. Is it possible that I do not have all libraries installed?
Edit:
As sehe pointed out, including the right header was the key.
#include <iostream>
#include <boost/functional/hash.hpp>
int main() {
int x = 100;
int y = 10;
size_t h = 0;
boost::hash_combine(h, x);
boost::hash_combine(h, y);
std::cout << h << std::endl;
}
Luke 24:5:
“Why do you look for the living among the dead?"
Most of boost is header-only. There's nothing to link. In the case of hash-combine, everything is templates so there's nothing that could be hidden from the header file.
This is the first time I try to learn OpenGL, I'm following the examples of a book. I'm doing it under OS X 10.8 with Xcode. The code is the following:
#include "Angel.h"
const int numPoints = 5000;
typedef vec2 point2;
void init(){
point2 points[numPoints];
point2 vertices[3] = {
point2(-1.0, -1.0), point2(0.0, 1.0), point2(1.0, -1.0)
};
points[0] = point2(0.25, 0.5);
for (int k = 1; k < numPoints; k++) {
int j = rand()%3;
points[k] = (points[k-1]+vertices[j])/2.0;
}
GLuint program = InitShader("vertex.glsl", "fragment.glsl");
glUseProgram(program);
GLuint abuffer;
glGenVertexArraysAPPLE(1, &abuffer);
glBindVertexArrayAPPLE(abuffer);
GLuint buffer;
glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);
GLuint location = glGetAttribLocation(program, "vPosition");
glEnableVertexAttribArray(location);
glVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0));
glClearColor(1.0, 1.0, 1.0, 1.0);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, numPoints);
glFlush();
}
int main(int argc, char** argv){
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(640, 480);
glutCreateWindow("Sierpinski Gasket");
init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
It compiles. But when I try to execute it the window does not appear. The problem arises when I call the init() function. Without it the window appears but with a black background. With it, there's no window. The code can be found here.
UPDATE
Apparently the program is exiting in the line GLuint program = InitShader("vertex.glsl", "fragment.glsl"); because it's not finding the shader-files. How can I tell the program to use the files? I mean I have the .glsl files in the same folder as the .h and .cpp but when Xcode builds the project the executable is not in the same place as the .glsl files. How to solve this within Xcode?
The GLSL files are loaded at the runtime of the program. So it's not XCode that doesn't find the files, but your program. The most likely cause is, that you used a relative path for the files (like in the code snippet you provided), but started your program with a working path that doesn't match up with the hardcoded file locations. Usually your program binary is built into a dedicated build directory.
A quick fix is copying the GLSL files into the same directory as the binary. The proper solution would be to place the filed in a well known location. In MacOS X you can use Application bundles for this. See in the MacOS X developer docs how to place application resources into the Application bundle and how to access them. XCode also provides tools to automatically copy files into the generated bundle.
Follow Below Step:
Select the project on the left panel.
Select the target and then select Build Phases
There you should fin a button called Add Build Phase
There will appear a box where you have to select the files (there's a little +sign). And be sure you selected Destination: Products directory
Build the project, run it and now it should work !!
If Xcode isn't importing the files, then check if it's adding it to the resource folder by going to Your project Name in the file chooser, build phases, Copy Bundle Resources and make sure your 2 files are in there.