I'm trying to use gcc to dynamically link to the lua library but I keep getting undefined references to every single lua function, including luaL_newstate.
Here's the code I'm trying to compile
#include <stdlib.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
int main(void)
{
lua_State *state = luaL_newstate();
lua_close(state);
return 0;
}
And here's the command I'm using
cls && gcc test.c -Ilua-5.4.2_Win64_dllw6_lib\include -Llua-5.4.2_Win64_dllw6_lib -llua54
I also tried static linking with -l:liblua54.a, changing the order of the parameters, and moving the files into the mingw64 include and lib folders and using those instead, but nothing seems to change anything.
I just started to learn Linux kernel programming, and one of the tutorials use the linux/init.h and the linux/module.h. and init.h holds the printk function, but init.h does not exists.
#include <linux/module.h>
#include <linux/init.h> // source file does not exists
int main(int argc, char const *argv[])
{
printk(); // undefined
return 0;
}
// gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)
Is there a replacement for that?
Has anybody tried using the i2c_smbus_write_byte or any similar function on Raspberry Pi 4?
I can't get it compile it fails at the linking with not finding it.
I'm using it as described here: http://synfare.com/599N105E/hwdocs/rpi/rpii2c.html
All the headers recommended are there is and also the -li2c in the Makefile.
Can anybody tell what the problem can be? I have no clue at the moment.
Might be worth checking to see if libi2c-dev is present on your system.
sudo apt-get install libi2c-dev
may be all that you need.
The page you are linking to says:
With the Buster version, as of june 2019, the necessary details for
using i2c_smbus_write_byte_data() and siblings, require the following
include statements:
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <i2c/smbus.h>
Using fgrep you can confirm that the function is declared in the /usr/include/i2c/smbus.h:
# cd /usr/include; fgrep -R i2c_smbus_write_byte *
i2c/smbus.h:extern __s32 i2c_smbus_write_byte(int file, __u8 value);
i2c/smbus.h:extern __s32 i2c_smbus_write_byte_data(int file, __u8 command, __u8 value);
So this should work:
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include <i2c/smbus.h>
int main(void) {
int i2c = open("/dev/i2c-1", O_RDWR);
i2c_smbus_write_byte(i2c, 1);
close(i2c);
return 0;
}
I tested that this example compiles successfully in the latest Raspbian Buster Lite:
gcc test.c -otest -li2c
If you are using g++ instead of gcc, then you should wrap the include directives with extern "C":
extern "C" {
#include <linux/i2c-dev.h>
#include <i2c/smbus.h>
}
I've been trying to get cgraph (https://graphviz.gitlab.io/_pages/pdf/cgraph.pdf) working so I read and write some graph files. I tried writing some very basic code:
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <memory.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#include <mysql.h>
#include <graphviz/cgraph.h>
int main() {
FILE *fp = NULL;
fp = fopen("test.dot", "w+");
if (fp == NULL) {
return -1;
}
Agraph_t *g;
g = agopen("test", Agdirected, NULL);
Agnode_t *signal1;
signal1 = agnode(g, "Signal1_ON", TRUE);
Agnode_t *signal2;
signal2 = agnode(g, "Signal1_OFF", TRUE);
Agedge_t *link = agedge(g, signal1, signal2, "link1", TRUE);
agattr(g, AGEDGE, "label", "transitionlink");
agwrite(g, fp);
fclose(fp);
system("pause");
return 0;
}
What should be happening is that the file should be written to test.dot. This code works perfectly fine on Win64 release, but fails on Win64 debug, Win32 debug, and Win32 release. I have double checked the .lib files and .dll files settings in visual studio and in the file directories, making sure to copy the release and debug versions of each platform correctly. However, the agwrite keeps causing a "Microsoft Visual Studio C Runtime Library has detected a fatal error" crash on Win64 debug, Win32 debug, and Win32 release. The weird thing is if I change
agwrite(g, fp); to agwrite(g, stdout);, the code works on all platforms/configurations. I am so confused why this is happening. Here is the source file which contains the code for agwrite if that helps: https://github.com/ellson/MOTHBALLED-graphviz/blob/master/lib/cgraph/write.c
I cannot debug the issue because the source has been compiled into .dlls, and .libs for each platform/configuration.
I appreciate any suggestions/feedback,
Thank you
Edit:
For anyone godly enough to try and get this working on their own system, here are all my binaries, libs, and include files: https://www.dropbox.com/sh/o9tjz7txu4m0k5q/AAAnp8Wu99q9IsFN7kvqZP7Ta?dl=0
Edit 2:
The compiler I am using is MSVC 14 on Windows 10.
I found out that using cgraph directly results in an error when trying to use agwrite(). The solution is to use the GVC abstraction layer which comes with the Graphviz C API to do file I/O. Here is the code that worked:
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <memory.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Windows.h>
#include <mysql.h>
#include <graphviz/gvc.h>
int main() {
GVC_t *gvc;
gvc = gvContext();
Agraph_t *g;
g = agopen("test", Agdirected, NULL);
Agnode_t *signal1;
signal1 = agnode(g, "Signal1_ON", TRUE);
Agnode_t *signal2;
signal2 = agnode(g, "Signal1_OFF", TRUE);
Agedge_t *link = agedge(g, signal1, signal2, "link1", TRUE);
agattr(g, AGEDGE, "label", "transitionlink");
gvLayout(gvc, g, "dot");
gvRenderFilename(gvc, g, "dot", "test.dot");
gvFreeLayout(gvc, g);
agclose(g);
gvFreeContext(gvc);
system("pause");
return 0;
}
Edit:
Here is the documentation for GVC: https://graphviz.gitlab.io/_pages/pdf/gvc.3.pdf
The reason of crashing is described on official Graphviz site:
This usually happens when the Graphviz library is built using one version of the stdio library, and the user’s program is compiled using another. If the FILE structure of stdio is different, the call to agread() will cause a crash. This is mainly a problem on Windows where we just provide a binary release built with one version of Visual Studio and stdio changes depending on the version of Visual Studio. It can also occur if the user tries to use cygwin or something similar which may also use an incompatible stdio.
https://graphviz.org/faq/#FaqAgreadCrash
Hello I'm attempting to encode videos using the C ffmpeg libraries. For some reason, when I attempt to create a format context I get an error with:
[NULL # 0x7ff574006600] Requested output format 'mp4' is not a suitable output format
I know that my ffmpeg is compiled with the x264 flags, as a simple
ffmpeg -i test.mov test.mp4
works fine. I'm also linking with all of the generated pch files and everything else from the libav* libraries is working fine. Here's a full working example with the error's I'm recieving:
#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>
#include <libswscale/swscale.h>
#include <libavutil/opt.h>
#include <libswscale/swscale.h>
#include <libavutil/imgutils.h>
#include <stdio.h>
int main() {
AVFormatContext * output = NULL;
// now lets initialize the actual format element
if (avformat_alloc_output_context2(&output, NULL, "mp4", "test.mp4") < 0) {
printf("%s", "INVALID");
}
return 0;
}
You have to call
av_register_all();
prior to allocating the output context.