How to Remove Warning: Link.Res Contains Output Sections; Did You Forget -T

How to remove warning: link.res contains output sections; did you forget -T?

It's a bug in certain LD versions. Just ignore it for now, or see if your distro has an update for your LD. (package binutils)

http://www.freepascal.org/faq.var#unix-ld219

Linking SDL_image errors

You are looking for SDL_image, which provides libSDL_image.so. It is a seperate library.

Try and install that library. The package is usually named SDL_image.

You can also grab it here: http://www.libsdl.org/projects/SDL_image/

Edit: About the difference between package X and X-devel:

Libraries are of the form lib${Name}.so.${Version}. There can be subversions, too. The version is here to differenciate between incompatible versions, for example libpng 1.4 and 1.5 are not binary compatible.

When you link your program to your library, you could link to an exact version number (eg gcc test.c /usr/lib/libSDL_image-1.2.so.0.8.2 directly), but you usually don't really care about the exact version number, this is why we create a dynamic link: libSDL_image-1.2.so. This link will point to the exact version number.

Usually, on distributions, users who only want runtime files need neither header files, nor those dynamic links. Before, you probably had libSDL_image-1.2.so.${some_number} in /usr/lib, but the libSDL_image-1.2.so dynamic link was missing. It is provided by the SDL_image-devel packages.

How to place a variable at a given absolute address in memory (with GCC)

I don't know, but you can easily create a workaround like this:

int *var = (int*)0x40001000;
*var = 4;

It's not exactly the same thing, but in most situations a perfect substitute. It will work with any compiler, not just GCC.

If you use GCC, I assume you also use GNU ld (although it is not a certainty, of course) and ld has support for placing variables wherever you want them.

I imagine letting the linker do that job is pretty common.

Inspired by answer by @rib, I'll add that if the absolute address is for some control register, I'd add volatile to the pointer definition. If it is just RAM, it doesn't matter.

Why this record structure is compiling but giving runtime error

Progs is a dynamic array and has to be allocated before use.

For example:

SetLength(Progs,2);  // Allocates two records

See Dynamic Array

How do I address unchecked cast warnings?

Wow; I think I figured out the answer to my own question. I'm just not sure it's worth it! :)

The problem is the cast isn't checked. So, you have to check it yourself. You can't just check a parameterized type with instanceof, because the parameterized type information is unavailable at runtime, having been erased at compile time.

But, you can perform a check on each and every item in the hash, with instanceof, and in doing so, you can construct a new hash that is type-safe. And you won't provoke any warnings.

Thanks to mmyers and Esko Luontola, I've parameterized the code I originally wrote here, so it can be wrapped up in a utility class somewhere and used for any parameterized HashMap. If you want to understand it better and aren't very familiar with generics, I encourage viewing the edit history of this answer.

public static <K, V> HashMap<K, V> castHash(HashMap input,
Class<K> keyClass,
Class<V> valueClass) {
HashMap<K, V> output = new HashMap<K, V>();
if (input == null)
return output;
for (Object key: input.keySet().toArray()) {
if ((key == null) || (keyClass.isAssignableFrom(key.getClass()))) {
Object value = input.get(key);
if ((value == null) || (valueClass.isAssignableFrom(value.getClass()))) {
K k = keyClass.cast(key);
V v = valueClass.cast(value);
output.put(k, v);
} else {
throw new AssertionError(
"Cannot cast to HashMap<"+ keyClass.getSimpleName()
+", "+ valueClass.getSimpleName() +">"
+", value "+ value +" is not a "+ valueClass.getSimpleName()
);
}
} else {
throw new AssertionError(
"Cannot cast to HashMap<"+ keyClass.getSimpleName()
+", "+ valueClass.getSimpleName() +">"
+", key "+ key +" is not a " + keyClass.getSimpleName()
);
}
}
return output;
}

That's a lot of work, possibly for very little reward... I'm not sure if I'll use it or not. I'd appreciate any comments as to whether people think it's worth it or not. Also, I'd appreciate improvement suggestions: is there something better I can do besides throw AssertionErrors? Is there something better I could throw? Should I make it a checked Exception?



Related Topics



Leave a reply



Submit