Weird errors when calling aiGetMaterialFloat (ASSIMP, C) - c

I am following Assimp's documentation to retrieve properties from a struct aiMaterial type. From their documentation, this is the usage of aiGetMaterialString():
aiGetMaterialFloat(mat,<material-key>,<where-to-store>)
I was able to get the material name using aiGetMaterialString() and a propertie's color with aiGetMaterialColor(), for example, but adding this to my code:
float f = 1.0f;
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS, (float*)&f);
results in:
gcc src/*.c examples/game.c -o bin/game.o -lGL -lGLEW -lSDL2 -lSDL2_image -lassimp -lm
In file included from /usr/include/assimp/scene.h:53:0,
from src/../include/mesh.h:13,
from src/mesh.c:1:
src/mesh.c: In function ‘mesh_setMaterialData’:
src/mesh.c:71:2: error: ‘pMat’ undeclared (first use in this function)
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS, (float*)&f);
^
src/mesh.c:71:2: note: each undeclared identifier is reported only once for each function it appears in
src/mesh.c:71:2: error: ‘type’ undeclared (first use in this function)
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS, (float*)&f);
^
src/mesh.c:71:2: error: ‘pKey’ undeclared (first use in this function)
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS, (float*)&f);
^
src/mesh.c:71:2: error: ‘pOut’ undeclared (first use in this function)
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS, (float*)&f);
^
src/mesh.c:71:2: error: expected ‘;’ before ‘aiGetMaterialFloatArray’
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS, (float*)&f);
^
make: *** [makefile:2: ALL] Error 1
(in my code, mat is of type struct aiMaterial*).
The code I am using is also basically the same thing that's described in assimp/material.h, line 1363:
float specStrength = 1.f; // default value, remains unmodified if we fail.
aiGetMaterialFloat(mat, AI_MATKEY_SHININESS_STRENGTH,
(float*)&specStrength);
Could anyone explain to me what I am doing wrong?
Thank you.
Edit:
This is the definition of aiGetMaterialFloat
#define aiGetMaterialFloat (pMat, type, index, pKey, pOut) \
aiGetMaterialFloatArray(pMat, type, index, pKey, pOut, NULL)
and aiGetMaterialFloatArray
ASSIMP_API C_ENUM aiReturn aiGetMaterialFloatArray(const C_STRUCT aiMaterial* pMat, const char* pKey, unsigned int type, unsigned int index, float* pOut, unsigned int* pMax);
I replaced what I had earlier with:
aiGetMaterialFloatArray(mat, AI_MATKEY_SHININESS, &f, NULL);
and it compiles... If I swap around the arguments on this function call I can get gcc to tell me that the 4th argument I send is actually being perceived as the 6th for aiGetMaterialFloatArray (unsigned int* pMax). I really don't know enough about macros to understand what is going on.

Related

Trouble building git-credential-libsecret: unknown type name ‘SecretService’

I'm trying to compile the git-credential-libsecret.c in /usr/share/doc/git/contrib/credential/libsecret by running sudo make on the Makefile there.
However, this fails with the following output:
gcc -g -O2 -Wall -pthread -I/usr/include/libsecret-1 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -o git-credential-libsecret.o -c git-credential-libsecret.c
git-credential-libsecret.c: In function ‘keyring_get’:
git-credential-libsecret.c:87:2: error: unknown type name ‘SecretService’
SecretService *service = NULL;
^
git-credential-libsecret.c:95:2: warning: implicit declaration of function ‘secret_service_get_sync’ [-Wimplicit-function-declaration]
service = secret_service_get_sync(0, NULL, &error);
^
git-credential-libsecret.c:95:10: warning: assignment makes pointer from integer without a cast [enabled by default]
service = secret_service_get_sync(0, NULL, &error);
^
git-credential-libsecret.c:103:2: warning: implicit declaration of function ‘secret_service_search_sync’ [-Wimplicit-function-declaration]
items = secret_service_search_sync(service,
^
git-credential-libsecret.c:106:9: error: ‘SECRET_SEARCH_LOAD_SECRETS’ undeclared (first use in this function)
SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK,
^
git-credential-libsecret.c:106:9: note: each undeclared identifier is reported only once for each function it appears in
git-credential-libsecret.c:106:38: error: ‘SECRET_SEARCH_UNLOCK’ undeclared (first use in this function)
SECRET_SEARCH_LOAD_SECRETS | SECRET_SEARCH_UNLOCK,
^
git-credential-libsecret.c:117:3: error: unknown type name ‘SecretItem’
SecretItem *item;
^
git-credential-libsecret.c:118:3: error: unknown type name ‘SecretValue’
SecretValue *secret;
^
git-credential-libsecret.c:122:3: warning: implicit declaration of function ‘secret_item_get_secret’ [-Wimplicit-function-declaration]
secret = secret_item_get_secret(item);
^
git-credential-libsecret.c:122:10: warning: assignment makes pointer from integer without a cast [enabled by default]
secret = secret_item_get_secret(item);
^
git-credential-libsecret.c:123:3: warning: implicit declaration of function ‘secret_item_get_attributes’ [-Wimplicit-function-declaration]
attributes = secret_item_get_attributes(item);
^
git-credential-libsecret.c:123:14: warning: assignment makes pointer from integer without a cast [enabled by default]
attributes = secret_item_get_attributes(item);
^
git-credential-libsecret.c:131:3: warning: implicit declaration of function ‘secret_value_get_text’ [-Wimplicit-function-declaration]
s = secret_value_get_text(secret);
^
git-credential-libsecret.c:131:5: warning: assignment makes pointer from integer without a cast [enabled by default]
s = secret_value_get_text(secret);
^
git-credential-libsecret.c:138:3: warning: implicit declaration of function ‘secret_value_unref’ [-Wimplicit-function-declaration]
secret_value_unref(secret);
^
make: *** [git-credential-libsecret.o] Error 1
From what I can tell the errors are stemming from the unknown type name issues and them spiralling out as the unknown types are used "incorrectly" later on.
As near as I can tell, however, the types are perfectly well defined in the locations provided in the source files:
grep -Enr "#include.*secret\.h" git-credential-libsecret.c
30:#include <libsecret/secret.h>
Per the gcc call, this will be found at /usr/include/libsecret-1, and indeed:
ls /usr/include/libsecret-1/libsecret
secret-attributes.h secret-enum-types.h secret-item.h secret-paths.h secret-schema.h secret-service.h secret-value.h
secret-collection.h secret.h secret-password.h secret-prompt.h secret-schemas.h secret-types.h
This header itself doesn't define SecretService (grep -E "^typedef" secret.h gives nothing), because the SecretService is defined in secret-service.h:
grep -nE "^typedef.*SecretService;" /usr/include/libsecret-1/libsecret/secret-service.h
53:typedef struct _SecretService SecretService;
And secret-service is included in secret.h:
grep -En "^#include.*service" /usr/include/libsecret-1/libsecret/secret.h
40:#include <libsecret/secret-service.h>
Similar investigations yield the same for SecretItem and SecretValue.
Am I missing something? Why doesn't the file build as expected?

I can't compile SDL_net in MinGW

Every time i try to compile SDL_net it says
SDLnet.c: In function 'SDLNet_GetLocalAddresses':
SDLnet.c:215:69: error: 'ERROR_BUFFER_OVERFLOW' undeclared (first use in this function)
if ((dwRetVal = GetAdaptersInfo(pAdapterInfo, &ulOutBufLen)) == ERROR_BUFFER_OVERFLOW) {
^~~~~~~~~~~~~~~~~~~~~
SDLnet.c:215:69: note: each undeclared identifier is reported only once for each function it appears in
SDLnet.c:223:21: error: 'NO_ERROR' undeclared (first use in this function)
if (dwRetVal == NO_ERROR) {
^~~~~~~~
make: *** [SDLnet.lo] Error 1
https://www.vogons.org/viewtopic.php?f=31&t=55706#p609435
Use my Mingw guide, it's in the Google Drive link

C library linking in linux

I have been working on a C code for which I needed some functions of libxls.h header files. I have already downloaded the corresponding files and followed the installation instruction. The files also contained a test C code (test.c) which I tried compiling. The results were as follow:
Command to compile the test.c file-
gcc test.c -lm
Results:
[root#XXXXXXX95549 test]# gcc test.c -lm
test.c:28:24: error: libxls/xls.h: No such file or directory
test.c: In function ‘main’:
test.c:33: error: ‘xlsWorkBook’ undeclared (first use in this function)
test.c:33: error: (Each undeclared identifier is reported only once
test.c:33: error: for each function it appears in.)
test.c:33: error: ‘pWB’ undeclared (first use in this function)
test.c:34: error: ‘xlsWorkSheet’ undeclared (first use in this function)
test.c:34: error: ‘pWS’ undeclared (first use in this function)
test.c:39: error: ‘WORD’ undeclared (first use in this function)
test.c:39: error: expected ‘;’ before ‘t’
test.c:53: error: ‘t’ undeclared (first use in this function)
test.c:58: error: ‘tt’ undeclared (first use in this function)
test.c:60: error: dereferencing pointer to incomplete type
test.c:63: error: dereferencing pointer to incomplete type
test.c:64: error: dereferencing pointer to incomplete type
test.c:66: error: dereferencing pointer to incomplete type
test.c:67: error: dereferencing pointer to incomplete type
test.c:68: error: dereferencing pointer to incomplete type
test.c:70: error: dereferencing pointer to incomplete type
test.c:70: error: dereferencing pointer to incomplete type
test.c:71: error: dereferencing pointer to incomplete type
To solve this problem, I copied the library files at the '/user/include' location
After which the results for same compilation commands were:
[root#XXXXXX95549 test]# gcc test.c -lm
/tmp/cc8DJETV.o: In function `main':
test.c:(.text+0x14): undefined reference to `xls_open'
test.c:(.text+0xd4): undefined reference to `xls_getWorkSheet'
test.c:(.text+0xe4): undefined reference to `xls_parseWorkSheet'
test.c:(.text+0xf0): undefined reference to `xls_getCSS'
test.c:(.text+0x49c): undefined reference to `xls_showBookInfo'
collect2: ld returned 1 exit status
Please, explain how can I rectify this problem.
The code test.c is given below:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <libxls/xls.h>
int main()
{
xlsWorkBook* pWB;
xlsWorkSheet* pWS;
FILE *f;
int i;
struct st_row_data* row;
WORD t,tt;
pWB=xls_open("files/test2.xls", "ASCII"); // "KOI8-R"
if (pWB!=NULL)
{
f=fopen ("test.htm", "w");
for (i=0;i<pWB->sheets.count;i++)
printf("Sheet N%i (%s) pos %i\n",i,pWB->sheets.sheet[i].name,pWB->sheets.sheet[i].filepos);
pWS=xls_getWorkSheet(pWB,0);
xls_parseWorkSheet(pWS);
fprintf(f,"<style type=\"text/css\">\n%s</style>\n",xls_getCSS(pWB));
fprintf(f,"<table border=0 cellspacing=0 cellpadding=2>");
for (t=0;t<=pWS->rows.lastrow;t++)
{
row=&pWS->rows.row[t];
// xls_showROW(row->row);
fprintf(f,"<tr>");
for (tt=0;tt<=pWS->rows.lastcol;tt++)
{
if (!row->cells.cell[tt].ishiden)
{
fprintf(f,"<td");
if (row->cells.cell[tt].colspan)
fprintf(f," colspan=%i",row->cells.cell[tt].colspan);
// if (t==0) fprintf(f," width=%i",row->cells.cell[tt].width/35);
if (row->cells.cell[tt].rowspan)
fprintf(f," rowspan=%i",row->cells.cell[tt].rowspan);
fprintf(f," class=xf%i",row->cells.cell[tt].xf);
fprintf(f,">");
if (row->cells.cell[tt].str!=NULL && row->cells.cell[tt].str[0]!='\0')
fprintf(f,"%s",row->cells.cell[tt].str);
else
fprintf(f,"%s"," ");
fprintf(f,"</td>");
}
}
fprintf(f,"</tr>\n");
}
fprintf(f,"</table>");
printf("Count of rows: %i\n",pWS->rows.lastrow);
printf("Max col: %i\n",pWS->rows.lastcol);
printf("Count of sheets: %i\n",pWB->sheets.count);
fclose(f);
xls_showBookInfo(pWB);
}
return 0;
}
Thanks in advance,
Got the answer to this question on the following location:
http://www.cprogramdevelop.com/2018568/
Those who might be facing the problem with libxls library can refer the above mentioned website.
cheers

understanding some source code

gcc 4.7.2
c89
Hello,
I am reviewing someones source code, and I have come across this.
I have this declaration and definition that I don't understand what it does. I know that the static means that it will not be exported out of the file.
static SERVICE_STATUS_HANDLE g_win_status_handle = NULL;
Because it is set to NULL it looks like a pointer. SERVICE_STATUS_HANDLE isnt' defined anywhere else. Only this file.
It is being used like this, is this comparing if g_win_status_handle is equal to NULL after SERVICE_STATUS_HANDLE is casted to 0 or NULL:
if(g_win_status_handle == (SERVICE_STATUS_HANDLE)0) {
/* do something */
}
And like this:
if(!SetServiceStatus(g_win_status_handle, &g_win_status)) {
/* do something */
}
Many thanks if someone can shed some light on this.
i have made small program
#include<stdio.h>
static SERVICE_STATUS_HANDLE g_win_status_handle = NULL;
int main()
{
if(g_win_status_handle == (SERVICE_STATUS_HANDLE)0) {
printf("ksdfbhdejkfb");
}
return 0;
}
compiled on gcc (GCC) 4.5.1 20100924 (Red Hat 4.5.1-4)
with c89 flags, like
gcc -std=c89 temp.c
its giving error
temp.c:3:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘g_win_status_handle’
temp.c: In function ‘main’:
temp.c:6:4: error: ‘g_win_status_handle’ undeclared (first use in this function)
temp.c:6:4: note: each undeclared identifier is reported only once for each function it appears in
temp.c:6:28: error: ‘SERVICE_STATUS_HANDLE’ undeclared (first use in this function)
temp.c:6:50: error: expected ‘)’ before numeric constant
Here it is obvious that SERVICE_STATUS_HANDLE must be defined some where.. if not defined then how your code is going to even compile?
May be it will be defined in some header file..
Updated answer from comments
SERVICE_STATUS_HANDLE is defined in windows.h and its going to include.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383751%28v=vs.85%29.aspx

Eclipse goto label not working in C

I am using the Eclipse CDT and I have a goto label and a FILE definition after it and when I compile the project it gives me the error: Expression expected before FILE.
Thanks in advance,
Mr. Man
EDIT:
Ok, so this is what I get from the command line:
iOS.c: In function ‘main’:
iOS.c:45: error: expected expression before ‘FILE’
iOS.c:49: error: ‘preFile’ undeclared (first use in this function)
iOS.c:49: error: (Each undeclared identifier is reported only once
iOS.c:49: error: for each function it appears in.)`
And this is what code throws the error:
fileExists:
FILE *preFile = fopen("prefix.txt","r");
As you're coding in C, you need to declare the variable at the beginning of the function:
void foo()
{
FILE* preFile;
// some code
fileExists:
preFile = fopen("prefix.txt","r");
}

Resources