I have one problem with library <bcrypt.h>. Compiler say error with function bcrypt_gensalt.
#include <iostream>
#include <bcrypt.h>
using namespace std;
int main() {
const char* passwd = "Secret_Password";
char results[BCRYPT_HASHSIZE];
bcrypt_gensalt(10, results);
system("pause");
return 0;
}
Error from compiler:
unresolved external symbol bcrypt_gensalt referenced in function main
You need to reference Bcrypt.lib.
See here: http://msdn.microsoft.com/en-us/library/ba1z7822.aspx.
Related
I must use main() and call a function from windows.h.
The following code wants a WinMain() function to be used instead of main().
#include <windows.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int vk_Shift = 16;
while (1)
{
if (GetAsyncKeyState(vk_Shift) < 0)
{
printf("Shift is pressed\n");
}
}
}
Error
Error 1 error LNK2019: unresolved external symbol _WinMain#16
referenced in function ___tmainCRTStartup
Error 2 error LNK1120: 1 unresolved externals
How can I get this work in VS2013?
Okay, guys, I got it.
Felix Palmen's advice works.
... ... I guess configuring it as "console" application should do the trick.
So, what I did is, I changed my project's preference from WIDOWS to CONSOLE.
When I try to compile my code, I'm getting the error:
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_init (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_lock (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_unlock (referred from lab4_t0.o).
I read that "Undefined symbol errors can occur when a function is declared (as is the case for the lock functions in lock.h), but it is not properly implemented." But I feel that I am implementing all the functions in lock.h properly since all the functions are of type voidand I don't return anything. So I don't know what I could be doing wrong to get this error.
Any help would greatly be appreciated!
Note: Please let me know if I need to provide more code. I don't think I need to write what I put in the function implementations of lock.h since I feel all you need to know is that the function implementations do not return anything, but please let me know if I need to include that.
Code
lock.c
#include "lock.h"
extern process_t * current_process;
extern process_t * process_queue;
void l_init(lock_t* l){
//Does stuff but never type return or return anything
}
void l_lock(lock_t* l){
//Does stuff but never type return or return anything
}
void l_unlock(lock_t* l){
//Does stuff but never type return or return anything
}
lock.h
#ifndef __LOCK_H_INCLUDED__
#define __LOCK_H_INCLUDED__
#include "3140_concur.h"
#include "shared_structs.h"
void l_init(lock_t* l);
void l_lock(lock_t* l);
void l_unlock(lock_t* l);
#endif /* __LOCK_H_INCLUDED */
3140_concur.c
#include "3140_concur.h"
#include <stdlib.h>
3140_concur.h
#ifndef __3140_CONCUR_H__
#define __3140_CONCUR_H__
#include <stdlib.h>
#include <fsl_device_registers.h>
#include "process.h"
void process_blocked (void);
void process_terminated (void);
unsigned int * process_stack_init (void (*f)(void), int n);
void process_stack_free (unsigned int *sp, int n);
void process_begin (void);
#endif
process.h
#include <stdlib.h>
#include <fsl_device_registers.h>
#include "3140_concur.h"
struct process_state;
typedef struct process_state process_t;
unsigned int * process_select (unsigned int * cursp);
extern process_t * current_process;
extern process_t * process_queue;
void process_start (void);
int process_create (void (*f)(void), int n);
process.c
(I do process_t* process_queue = NULL; & process_t* current_process = NULL; b/c I want them to be NULL before any functions are called)
#include "3140_concur.h"
#include "shared_structs.h"
#include <stdlib.h>
#include <fsl_device_registers.h>
process_t* process_queue = NULL;
process_t* current_process = NULL;
lab4_t0.c
#include "process.h"
#include "utils.h"
#include "lock.h"
lock_t l;
\\uses functions in lock.h
Update
Build output
*** Using Compiler 'V5.06 update 4 (build 422)', folder: 'C:\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
compiling 3140_concur.c...
compiling lab4_t0.c...
lab4_t0.c(42): warning: #111-D: statement is unreachable
return 0;
lab4_t0.c: 1 warning, 0 errors
compiling process.c...
process.c(100): warning: #1-D: last line of file ends without a newline
}
process.c: 1 warning, 0 errors
linking...
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_init (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_lock (referred from lab4_t0.o).
.\Objects\Lab4.axf: Error: L6218E: Undefined symbol l_unlock (referred from lab4_t0.o).
Not enough information to list image symbols.
Finished: 1 information, 0 warning and 3 error messages.
".\Objects\Lab4.axf" - 3 Error(s), 2 Warning(s).
Target not created.
Build Time Elapsed: 00:00:39
Thanks to #AjayBrahmakshatriya, it turns out I didn't add lock.c to my project. That fixed everything. Whew.
I tried making this simple static library in Code::Blocks with MinGW:
#include <time.h>
#include <sys/time.h>
#include "header.h"
extern int go(int x)
{
struct timeval t;
gettimeofday(&t, NULL);
return 1;
}
This same snippet works if compiled as a console app (with printf), but when compiled as a static library, the calling code keeps getting this error:
unresolved external symbol "_gettimeofday"
I'm trying to access the programs array in my main file. It is declared in the header file and initialized in a separate module called fileReader. The error message I receive is
Undefined symbols for architecture x86_64:
"_programs", referenced from:
_main in test-0bf1e8.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "header.h"
#include "fileReader.c"
int main() {
readPrograms();
for (int i=0; i<4; i++) {
printf("%s", programs[i]);
}
return 0;
}
fileReader.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "header.h"
int readPrograms() {
int i=0;
int numProgs=0;
char* programs[50];
char line[50];
FILE *file;
file = fopen("files.txt", "r");
while(fgets(line, sizeof(line), file)!=NULL) {
//add each filename into array of programs
programs[i]=strdup(line);
i++;
}
fclose(file);
return 0;
}
header.h
extern char* programs[];
Thanks in advance
You are not supposed to include C files from other C files, only the header files.
Here is what you need to fix:
Add a prototype of readPrograms function to the header.h
Remove #include "fileReader.c" from the main.c file
Add a definition of programs array to one of your C files (say, main.c).
Remove declaration of the local programs from readPrograms
The definition of programs that you put in main.c should look like this:
char* programs[50];
You can put it before or after your main() function.
I would like to to use DwfToolkit in my app, but I have problem to link it.
The code:
// DWF Core headers
#include "dwfcore/String.h"
#include "dwfcore/Core.h"
#include "dwfcore/SkipList.h"
#include "dwfcore/InputStream.h"
using namespace DWFCore;
// WHIP! headers
#include "whiptk/whip_toolkit.h"
// DWF Toolkit headers
#include "dwf/Version.h"
#include "dwf/Toolkit.h"
#include "dwf/package/Manifest.h"
#include "dwf/package/EPlotSection.h"
#include "dwf/package/EModelSection.h"
using namespace DWFToolkit;
int _tmain(int argc, _TCHAR* argv[])
{
DWFString path("c:\\test.dwf");
DWFFile file(path);
DWFPackageReader reader( file );
return 0;
}
In linker options (Additional Dependencies) I added dwfcore.1.7.0.lib, dwftk_ro.7.7.0.lib, whiptk_ro.7.13.601.lib. After compile:
Error 902 error LNK2019: unresolved external symbol "__declspec(dllimport)
public: __thiscall DWFCore::DWFString::DWFString(wchar_t const *)"
(__imp_??0DWFString#DWFCore##QAE#PB_W#Z) referenced in function _wmain
When I erase line DWFPackageReader reader( file ); from code, program is builded.
If you are linking static lib add dwfcore_static in the preprocessor.