*This is my first programming course in over 20 years, so I am basically clueless.
I am trying to complete the last project in the course which includes installing and configuring SDL. Right now all I have is the basic "Hello World" code. I get the error when I add #include .
When I installed SDL, I copied the SDL2 folder and the entire lib folder to MinGW-w64 - as instructed by a tutorial.
I have MinGW-w64 installed. Here is the build error:
C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o):crt0_c.c:(.text.startup+0x2e): undefined reference to `WinMain'
collect2.exe: error: ld returned 1 exit status
I've been googling for hours and cannot seem to find any help.*
Edit:
Thank you both so much for your quick responses.
Here is what I did in settings:
Do I need to put an 'l' in front of these items?
I got some help elsewhere and added #define SDL_MAIN_HANDLED. This allowed the project to build, but it still doesn't run. I get nothing at all when I try to run it. I tried calling SDL_GetError(), but still nothing.
also make sure your main has the following signature:
int main(int, char**) - SDL is pretty militant about it
I'm trying to setup kotlin/native project that utilizes OpenGL C libraries.
OS: ArchLabs, linux 5.1.15 (shares repositories with arch)
Packages installed: glu, glew, freeglut, glfw
In my main() there's only one function called (it's copied from samples):
glutInit(argc.ptr, null)
There was no out of the box support for OpenGL in my project, so I decided to make opengl.def:
package = platform.OpenGL
headers = GL/glut.h
compilerOpts = -I/usr/include
$ ls /usr/include/GL
freeglut_ext.h glcorearb.h gl.h glu_mangle.h glxext.h glx_mangle.h glxtokens.h wglew.h
freeglut.h glew.h gl_mangle.h glut.h glx.h glxmd.h internal
freeglut_std.h glext.h glu.h glxew.h glxint.h glxproto.h osmesa.h
And here's my gradle.build.kts:
plugins {
id("org.jetbrains.kotlin.multiplatform") version "1.3.41"
}
repositories {
mavenCentral()
}
kotlin {
linuxX64("opengl") {
val main by compilations.getting
val opengl by main.cinterops.creating
binaries {
executable {
entryPoint = "opengl.main"
}
}
}
}
There is a .kt file generated: build/classes/.../OpenGL/OpenGL.kt which contains definition of glutInit function (well, more of a reference I guess)
And here's the output of runReleaseExecutableOpengl
> Configure project :
Kotlin Multiplatform Projects are an experimental feature.
> Task :cinteropOpenglOpengl
> Task :linkReleaseExecutableOpengl
/home/Opengl/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld: error: undefined symbol: glutInit
>>> referenced by ld-temp.o
>>> /tmp/konan_temp5065866915785286367/combined.o:(platform_OpenGL_kniBridge520)
e: /home/Opengl/.konan/dependencies/clang-llvm-6.0.1-linux-x86-64/bin/ld.lld invocation reported errors
> Task :linkReleaseExecutableOpengl FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':linkReleaseExecutableOpengl'.
> Process 'command '/usr/lib/jvm/java-11-openjdk/bin/java'' finished with non-zero exit value 1
Is there a way to fix it? My best guess is that I have to have mingw-w64-* packages installed, for example mingw-w64-freeglut. Is that the case? It could also be that I'm pointing to the wrong headers (I'm not really into C yet and it's been a long time since I used C++) and it can't find the implementation of these headers.
Thanks in advance!
You need linkerOpts = -L/usr/lib -lglut in the def file, to dynamically link against freeglut.
I'm developing a game, and am trying to use bullet. However, (it seems that) I am having trouble linking the bullet libraries. Edit 2: I have my code on github
This is actually my first time using cmake. I have searched through the FindBullet.cmake file, and could find the variable to link libraries(${BULLET_LIBRARIES}), but linking the libraries in the variable didn't do anything.
find_package(Bullet REQUIRED)
include_directories(${BULLET_INCLUDE_DIR})
target_link_libraries(3DPlatformer ${BULLET_LIBRARIES})
I expected the my code to compile but instead I got a bunch of, "undefined refrence to" then whatever function from bullet it read.
edit:
more undefined references to `btAlignedAllocInternal(unsigned long, int)' follow
^ thats what I got a bunch of
collect2: error: ld returned 1 exit status
And that is the last error.
Full Error
libbullet-dev need to be installed.
sudo apt-get install libbullet-dev
My issue is that one of my if statements was broken.
My if statement:
if(USE_SYSTEM_BULLET)
find_package(Bullet REQUIRED)
include_directories(${BULLET_INCLUDE_DIR})
target_link_libraries(3DPlatformer ${BULLET_LIBRARIES} -lGL -lGLU)
else(USE_SYSTEM_BULLET)
add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet" )
include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
endif(USE_SYSTEM_BULLET)
was somehow triggering all the code instead of some of it. commenting the code like this:
#if(USE_SYSTEM_BULLET)
find_package(Bullet REQUIRED)
include_directories(${BULLET_INCLUDE_DIR})
target_link_libraries(3DPlatformer ${BULLET_LIBRARIES} -lGL -lGLU)
#else(USE_SYSTEM_BULLET)
# add_subdirectory("${PROJECT_SOURCE_DIR}/lib/bullet" )
# include_directories("${PROJECT_SOURCE_DIR}/lib/bullet/src")
#endif(USE_SYSTEM_BULLET)
fixed it.
i'm trying to install connection between c++ and mysql in ubuntu 12.04. i've installed mysql-client, mysql-server, libmysqlclient15-dev, libmysql++-dev. but when i try to compile the code i got the error: mysql.h there is no such file. i looked in the folders, there is mysql.h file, i can't understand why it can't find it. here is my code:
/* Simple C program that connects to MySQL Database server*/
#include <mysql.h>
#include <stdio.h>
main() {
MYSQL *conn;
MYSQL_RES *res;
MYSQL_ROW row;
char *server = "localhost";
char *user = "root";
//set the password for mysql server here
char *password = "*********"; /* set me first */
char *database = "Real_flights";
conn = mysql_init(NULL);
/* Connect to database */
if (!mysql_real_connect(conn, server,
user, password, database, 0, NULL, 0)) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
/* send SQL query */
if (mysql_query(conn, "show tables")) {
fprintf(stderr, "%s\n", mysql_error(conn));
exit(1);
}
res = mysql_use_result(conn);
/* output table name */
printf("MySQL Tables in mysql database:\n");
while ((row = mysql_fetch_row(res)) != NULL)
printf("%s \n", row[0]);
/* close connection */
mysql_free_result(res);
mysql_close(conn);
}
it's worked, but now i'm facing another error like :
mysql.c: In function ‘main’:
mysql.c:21: warning: incompatible implicit declaration of built-in function ‘exit’
mysql.c:27: warning: incompatible implicit declaration of built-in function ‘exit’
/tmp/ccinQBp8.o: In function `main':
mysql.c:(.text+0x3e): undefined reference to `mysql_init'
mysql.c:(.text+0x5e): undefined reference to `mysql_real_connect'
mysql.c:(.text+0x70): undefined reference to `mysql_error'
mysql.c:(.text+0xa5): undefined reference to `mysql_query'
mysql.c:(.text+0xb7): undefined reference to `mysql_error'
mysql.c:(.text+0xe7): undefined reference to `mysql_use_result'
mysql.c:(.text+0x11c): undefined reference to `mysql_fetch_row'
mysql.c:(.text+0x133): undefined reference to `mysql_free_result'
mysql.c:(.text+0x141): undefined reference to `mysql_close'
collect2: ld returned 1 exit status
The mysql.h file from the libmysqlclient-dev Ubuntu package is located at /usr/include/mysql/mysql.h.
This is not a standard search path for compilers, however /usr/include is.
You'd typically use the mysql.h header in your code like this:
#include <mysql/mysql.h>
If you don't want to specify the directory offset in your source, you can pass the -I flag to gcc (If that's what you are using) to specify an additional include search directory, and then you wouldn't need to change your existing code.
eg.
gcc -I/usr/include/mysql ...
just use
$ apt-get install libmysqlclient-dev
which will automatically pull the latest libmysqlclient18-dev
I have seen older versions of libmysqlclient-dev (like 15) puts the mysql.h in weird locations e.g. /usr/local/include etc.
otherwise, just do a
$ find /usr/ -name 'mysql.h'
and put the folder path of your mysql.h with -I flag in your make file. Not clean but will work.
For CentOS/RHEL:
yum install mysql-devel -y
this worked for me
$ gcc dbconnect.c -o dbconnect -lmysqlclient
$ ./dbconnect
-lmysqlclient is must.
and i would recommend to use following notation instead of using -I compilation flag.
#include <mysql/mysql.h>
You probably don't included the path to mysql headers, which can be found at /usr/include/mysql, on several unix systems I think. See this post, it may be helpfull.
By the way, related with the question of that guy above, about syntastic configuration. One can add the following to your ~/.vimrc:
let b:syntastic_c_cflags = '-I/usr/include/mysql'
and you can always check the wiki page of the developers on github. Enjoy!
You have to let the compiler know where the mysql.h file can be found. This can be done by giving the path to the header before compiling. In IDEs you have a setting where you can give these paths.
This link gives you more info on what options to use while compiling.
To your second problem
You need to link the libraries. The linker needs to know where the library files are which has the implementation for the mysql functions that you use.
This link gives you more info on how to link libraries.
I think you can try this gcc -I/usr/include/mysql *.c -L/usr/lib/mysql -lmysqlclient -o *
For those who are using Eclipse IDE.
After installing the full MySQL together with mysql client and mysql server and any mysql dev libraries,
You will need to tell Eclipse IDE about the following
Where to find mysql.h
Where to find libmysqlclient library
The path to search for libmysqlclient library
Here is how you go about it.
To Add mysql.h
1. GCC C Compiler -> Includes -> Include paths(-l) then click + and add path to your mysql.h In my case it was /usr/include/mysql
To add mysqlclient library and search path to where mysqlclient library see steps 3 and 4.
2. GCC C Linker -> Libraries -> Libraries(-l) then click + and add mysqlcient
3. GCC C Linker -> Libraries -> Library search path (-L) then click + and add search path to mysqlcient. In my case it was /usr/lib64/mysql because I am using a 64 bit Linux OS and a 64 bit MySQL Database.
Otherwise, if you are using a 32 bit Linux OS, you may find that it is found at /usr/lib/mysql
This worked for me
yum install mysql
It will install mysql client and then
pip install mysqlclient
I'm trying to compile an run a very basic program given below (test.cpp) which calls the OpenNI class. You can see the files and dirs they're in here. Sorry that some characters screws up a little bit in the browser's encoding. I'm using the linux command: tree, if you know a better command tell me and I will update it.
File Structure
I'm following the guide here, see "GCC / GNU Make".
#include < stdio.h >
#include < OpenNI.h >
using namespace openni;
int
main ( void )
{
Status rc = OpenNI::initialize();
if (rc != STATUS_OK)
{
printf("\nInitialize failed\n%s\n", OpenNI::getExtendedError());
return 1;
}
printf("Hello, world!\n");
return 0;
}
Here is what I'm running in the command line to compile it (gcc 4.7.2):
gcc test.cpp -I../OpenNI-2.0.0/Include -L/home/evan/Code/OpenNi/Init -l OpenNI2 -o test
This works fine but when I run ./test I get the following error:
Initialize failed
DeviceDriver: library handle is invalid for file libOniFile.so
Couldn't understand file 'libOniFile.so' as a device driver
DeviceDriver: library handle is invalid for file libPS1080.so
Couldn't understand file 'libPS1080.so' as a device driver
Found no valid drivers in './OpenNI2/Drivers'
Thanks, any help would be much appreciated.
Instructions from your guide says, that
It is highly suggested to also add the "-Wl,-rpath ./" to your linkage command. Otherwise, the runtime linker will not find the libOpenNI.so file when you run your application. (default Linux behavior is to look for shared objects only in /lib and /usr/lib).
It seems you have exactly this problem -- it can not find some libraries. Try to add proper rpath (seems to be /home/evan/Code/OpenNi/Init/OpenNI2/Drivers in your case) to your compilation string.
I had the same issue after compiling this little "Hello World" with Eclipse and trying to run it in the command line.
The "Wl,-rpath=./" thing did not work for me.
As also discussed here it worked for me after setting some env. variables before execution:
export LD_LIBRARY_PATH="/path/to/OpenNI2:$LD_LIBRARY_PATH"
export OPENNI2_DRIVERS_PATH="/path/to/OpenNI2/Drivers"
export LD_LIBRARY_PATH="/path/to/OpenNI2/Drivers:$LD_LIBRARY_PATH"
Somewhere I got the info that the first two lines should be enough but it was the third line which is important. I does also work just with the third line.