does anybody know how I can compile with sdl_image libary? I can't find anything that works
The Big Programming Thread - Page 591
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
sabas123
Netherlands3122 Posts
does anybody know how I can compile with sdl_image libary? I can't find anything that works | ||
Ropid
Germany3557 Posts
| ||
sabas123
Netherlands3122 Posts
fatal error: SDL_image.h: No such file or directory | ||
Ropid
Germany3557 Posts
#include <bla.h> You can add a directory to the compiler's list through -I. That -ISDL_image means you tell it to search in a sub-directory "SDL_image" from where you are currently. If you use this in your source code: #include "bla.h" That will search for bla.h in the same directory as where your source is. | ||
sabas123
Netherlands3122 Posts
On February 21 2015 23:45 Ropid wrote: The compiler has a list of directories it looks at for header files that you use like this in your source code: #include <bla.h> You can add a directory to the compiler's list through -I. That -ISDL_image means you tell it to search in a sub-directory "SDL_image" from where you are currently. If you use this in your source code: #include "bla.h" That will search for bla.h in the same directory as where your source is. aaahhh thank you, I geuss I have to search for the libary location then. | ||
Ropid
Germany3557 Posts
On February 21 2015 23:48 sabas123 wrote: aaahhh thank you, I geuss I have to search for the libary location then. I just tried that pkg-config you use on my machine here and it looks like this: $ pkg-config --cflags --libs sdl2 -D_REENTRANT -I/usr/include/SDL2 -lSDL2 -lpthread That seems to list everything that should be needed for me. What's happening for you? How does the output look like? EDIT: But I just found out, if you're after SDL_image.h, that one is in another directory as it's SDL and not SDL2, so the options for it get found through: $ pkg-config --cflags --libs sdl -D_GNU_SOURCE=1 -D_REENTRANT -I/usr/include/SDL -lSDL -lpthread I see there's also another sdl2_image package on my Linux distro, not just sdl_image. Both have a SDL_image.h file in them. Perhaps you installed the wrong package? | ||
sabas123
Netherlands3122 Posts
I had libsdl1.2-image-dev and libsdl2-image but not libsdl2-image-dev that took me 2 hoursT_T | ||
nunez
Norway4003 Posts
| ||
sabas123
Netherlands3122 Posts
On February 22 2015 00:35 nunez wrote: noob! + Show Spoiler + | ||
sabas123
Netherlands3122 Posts
+ Show Spoiler + void merge(int *arr, int size1, int size2) { int temp[size1+size2]; int ptr1=0, ptr2=0; while (ptr1+ptr2 < size1+size2) { if (ptr1 < size1 && arr[ptr1] <= arr[size1+ptr2] || ptr1 < size1 && ptr2 >= size2) temp[ptr1+ptr2] = arr[ptr1++]; if (ptr2 < size2 && arr[size1+ptr2] < arr[ptr1] || ptr2 < size2 && ptr1 >= size1) temp[ptr1+ptr2] = arr[size1+ptr2++]; } for (int i=0; i < size1+size2; i++) arr[i] = temp[i]; } void mergeSort(int *arr, int size) { if (size == 1) return; int size1 = size/2, size2 = size-size1; mergeSort(arr, size1); mergeSort(arr+size1, size2); merge(arr, size1, size2); } | ||
Azerbaijan
United States660 Posts
| ||
Cynry
810 Posts
On February 22 2015 05:11 sabas123 wrote: trying to understand mergesort made me realize somethings are still confusing as hell T_T + Show Spoiler + void merge(int *arr, int size1, int size2) { int temp[size1+size2]; int ptr1=0, ptr2=0; while (ptr1+ptr2 < size1+size2) { if (ptr1 < size1 && arr[ptr1] <= arr[size1+ptr2] || ptr1 < size1 && ptr2 >= size2) temp[ptr1+ptr2] = arr[ptr1++]; if (ptr2 < size2 && arr[size1+ptr2] < arr[ptr1] || ptr2 < size2 && ptr1 >= size1) temp[ptr1+ptr2] = arr[size1+ptr2++]; } for (int i=0; i < size1+size2; i++) arr[i] = temp[i]; } void mergeSort(int *arr, int size) { if (size == 1) return; int size1 = size/2, size2 = size-size1; mergeSort(arr, size1); mergeSort(arr+size1, size2); merge(arr, size1, size2); } What's your issue with this one ? Recursivity ? | ||
Blisse
Canada3710 Posts
On February 22 2015 05:11 sabas123 wrote: trying to understand mergesort made me realize somethings are still confusing as hell T_T + Show Spoiler + void merge(int *arr, int size1, int size2) { int temp[size1+size2]; int ptr1=0, ptr2=0; while (ptr1+ptr2 < size1+size2) { if (ptr1 < size1 && arr[ptr1] <= arr[size1+ptr2] || ptr1 < size1 && ptr2 >= size2) temp[ptr1+ptr2] = arr[ptr1++]; if (ptr2 < size2 && arr[size1+ptr2] < arr[ptr1] || ptr2 < size2 && ptr1 >= size1) temp[ptr1+ptr2] = arr[size1+ptr2++]; } for (int i=0; i < size1+size2; i++) arr[i] = temp[i]; } void mergeSort(int *arr, int size) { if (size == 1) return; int size1 = size/2, size2 = size-size1; mergeSort(arr, size1); mergeSort(arr+size1, size2); merge(arr, size1, size2); } does your code work? what's with the ptr1 >= size1, that will never happen | ||
spinesheath
Germany8679 Posts
Don't do stuff like arr[size1+ptr2++]. What's even worse: temp[ptr1+ptr2] = arr[size1+ptr2++]. What's evaluated first, the left side array index or the right side postfix increment? Sure, it's properly defined, but that doesn't make it a good idea to write stuff like that. I'd assume you'd be less confused if you didn't try to be so fancy. | ||
Blisse
Canada3710 Posts
really just need to clean up the code and it should be a lot easier to read through + Show Spoiler + void merge(int* outArray, int aSize, int bSize) | ||
spinesheath
Germany8679 Posts
| ||
Blisse
Canada3710 Posts
On February 22 2015 21:56 spinesheath wrote: Duh, you already fixed it. Now I have nothing to say here. :p we should have like a "critique my code" thingie every once in a while | ||
sabas123
Netherlands3122 Posts
On February 22 2015 21:58 Blisse wrote: :p we should have like a "critique my code" thingie every once in a while ye that is a really good idea. the code I posted was a tutorial i got somewhere because I got to frustated after my own code not working after like 10 times lol. the part that confuses me about that program is when the merge is called. this is how i under stand it you give mergsort an array, -> it splits it and calls its self to infinty till there are only 2 in the array left - > starts merging. but wont it will just a unsorted array for each time it called itself, and when it is sorted it has only 2 numbers to merge. | ||
nunez
Norway4003 Posts
On February 22 2015 19:55 spinesheath wrote: Don't call stuff "ptr". What's that? "pointer", "peter", "pastor", "petrol"? Give your variables proper names. It's not even a pointer to begin with. Don't do stuff like arr[size1+ptr2++]. What's even worse: temp[ptr1+ptr2] = arr[size1+ptr2++]. What's evaluated first, the left side array index or the right side postfix increment? Sure, it's properly defined, but that doesn't make it a good idea to write stuff like that. I'd assume you'd be less confused if you didn't try to be so fancy. i'd prefer ptr (pronouned: ptr) to pointer if you are writing c++, it conforms to the standard and is terser. std::unique_ptr, std::shared_ptr, std::weak_ptr, etc... your other point is good and is worth a peep. this point is valid only as it pertains to evaluation order, and not precedence, or expressions in general. i avoid it myself, i am not familiar enough to resolve ambiguities for now. @ropid i get that partiucal kind of programming pleasure from only using #include<...>, so i always do -I./ in my projects. | ||
Ropid
Germany3557 Posts
On February 22 2015 23:14 sabas123 wrote: ye that is a really good idea. the code I posted was a tutorial i got somewhere because I got to frustated after my own code not working after like 10 times lol. the part that confuses me about that program is when the merge is called. this is how i under stand it you give mergsort an array, -> it splits it and calls its self to infinty till there are only 2 in the array left - > starts merging. but wont it will just a unsorted array for each time it called itself, and when it is sorted it has only 2 numbers to merge. You could think of it as some sort of math. Look at this: sort FHDCEAGB = merge (sort FHDC) (sort EAGB) = merge (merge (sort FH) (sort DC)) (sort EAGB) = merge (merge (merge (sort F) (sort H)) (sort DC)) (sort EAGB) = merge (merge (merge F H) (sort DC)) (sort EAGB) = merge (merge FH (sort DC)) (sort EAGB) = merge (merge FH (merge (sort D) (sort C))) (sort EAGB) = merge (merge FH (merge D C)) (sort EAGB) = merge (merge FH CD) (sort EAGB) = merge CDFH (sort EAGB) = merge CDFH (merge (sort EA) (sort GB)) = merge CDFH (merge (merge (sort E) (sort A)) (sort GB)) = merge CDFH (merge (merge E A) (sort GB)) = merge CDFH (merge AE (sort GB)) = merge CDFH (merge AE (merge (sort G) (sort B))) = merge CDFH (merge AE (merge G B)) = merge CDFH (merge AE BG) = merge CDFH ABEG = ABCDEFGH I regret starting with 8 elements and not just 4. T_T An alternative is thinking about it visually as some sort of tree graph that gets built up by the sort function and collapsed by the merge function. You could draw that on paper or something. You could also think about what's happening on the stack. That's what helped me with recursion. The local variables of functions are living inside layers on the stack. Each function call adds a new layer on top, returning from a function deletes that layer. Parameters are the same as variables (and you can btw. even use them and overwrite them in C). | ||
| ||